home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / network / entrez / client / objneten.c < prev    next >
Text File  |  1996-07-05  |  103KB  |  4,196 lines

  1. /*   objneten.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE                          
  5. *               National Center for Biotechnology Information
  6. *                                                                          
  7. *  This software/database is a "United States Government Work" under the   
  8. *  terms of the United States Copyright Act.  It was written as part of    
  9. *  the author's official duties as a United States Government employee and 
  10. *  thus cannot be copyrighted.  This software/database is freely available 
  11. *  to the public for use. The National Library of Medicine and the U.S.    
  12. *  Government have not placed any restriction on its use or reproduction.  
  13. *                                                                          
  14. *  Although all reasonable efforts have been taken to ensure the accuracy  
  15. *  and reliability of the software and data, the NLM and the U.S.          
  16. *  Government do not and cannot warrant the performance or results that    
  17. *  may be obtained by using this software or data. The NLM and the U.S.    
  18. *  Government disclaim all warranties, express or implied, including       
  19. *  warranties of performance, merchantability or fitness for any particular
  20. *  purpose.                                                                
  21. *                                                                          
  22. *  Please cite the author in any work or product based on this material.   
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  objneten.c
  27. *
  28. * Author:  Epstein
  29. *
  30. * Version Creation Date:   06/02/92
  31. *
  32. * $Revision: 4.0 $
  33. *
  34. * File Description: 
  35. *       object loaders for Network Entrez
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. * 8-16-94  Brylawski   Added loaders for on-the-fly text neighboring
  42.                        (EntrezNeighborText) and EntrezHierarchy 
  43. * ==========================================================================
  44. *
  45. *
  46. * RCS Modification History:
  47. * $Log: objneten.c,v $
  48.  * Revision 4.0  1995/07/26  13:54:59  ostell
  49.  * force revision to 4.0
  50.  *
  51.  * Revision 1.14  1995/07/11  12:30:36  epstein
  52.  * change CDECLs to LIBCALLs
  53.  *
  54.  * Revision 1.13  1995/07/10  19:38:23  epstein
  55.  * implement docsumX
  56.  *
  57.  * Revision 1.12  1995/06/23  15:58:49  kans
  58.  * added ResidueGraphDictionaryLoad to initialization
  59.  *
  60.  * Revision 1.11  1995/05/17  17:53:30  epstein
  61.  * add RCS log revision history
  62.  *
  63. */
  64.  
  65. #include <asnneten.h> /* the AsnTool header */
  66. #include <objacces.h>
  67. #include <accentr.h>
  68. #include <objmedli.h> /* the Medline interface */
  69. #include <objloc.h>   /* the 'Seqloc' interface */
  70. #include <objsset.h>  /* the 'SeqSet' interface */
  71. #include <objneten.h> /* the Entrez objects interface */
  72. #include <objall.h>
  73.  
  74.  
  75. static Boolean loaded = FALSE;
  76.  
  77. /*****************************************************************************
  78. *
  79. *   NetEntAsnLoad()
  80. *
  81. *****************************************************************************/
  82. Boolean LIBCALL
  83. NetEntAsnLoad(void)
  84. {
  85.     if (loaded)
  86.         return TRUE;
  87.         loaded = TRUE;
  88.  
  89.         if (! AllObjLoad()) {
  90.                 loaded = FALSE;
  91.                 return FALSE;
  92.         }
  93.  
  94. #ifdef Biostruc_supported
  95.         objmmdb1AsnLoad ();
  96.         objmmdb2AsnLoad ();
  97.         objmmdb3AsnLoad ();
  98.         ResidueGraphDictionaryLoad ();
  99. #endif
  100.  
  101.         if (! AsnLoad()) {
  102.                 loaded = FALSE;
  103.                 return FALSE;
  104.         }
  105.  
  106.         return TRUE;
  107. }
  108.  
  109.  
  110. /************************** EntrezIds ****************************************/
  111.  
  112. EntrezIdsPtr LIBCALL
  113. EntrezIdsNew(void)
  114. {
  115.         EntrezIdsPtr p;
  116.  
  117.         p = MemNew(sizeof(EntrezIds));
  118.         if (p != NULL)
  119.         {
  120.                 p->numid = 0;
  121.                 p->ids = NULL;
  122.         }
  123.         return p;
  124. }
  125.  
  126. EntrezIdsPtr LIBCALL
  127. EntrezIdsFree(EntrezIdsPtr p)
  128. {
  129.         if (p == NULL)
  130.                 return NULL;
  131.         MemFree (p->ids);
  132.         return MemFree(p);
  133. }
  134.                 
  135. EntrezIdsPtr LIBCALL
  136. EntrezIdsAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  137. {
  138.         DataVal av;
  139.         EntrezIdsPtr p;
  140.         AsnTypePtr atp;
  141.         Int4 num;
  142.  
  143.         if (!NetEntAsnLoad())
  144.                 return NULL;
  145.         
  146.         if (aip == NULL)
  147.                 return NULL;
  148.         
  149.         if (orig == NULL)
  150.                 atp = AsnReadId(aip, amp, ENTREZ_IDS);
  151.         else
  152.                 atp = AsnLinkType(orig, ENTREZ_IDS); /* link in local tree */
  153.  
  154.         if (atp == NULL)
  155.                 return NULL;
  156.  
  157.         p = EntrezIdsNew();
  158.         if (p == NULL)
  159.                 goto erret;
  160.  
  161.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  162.                 goto erret;
  163.         atp = AsnReadId(aip, amp, atp); /* find the num */
  164.         if (atp == NULL)
  165.                 goto erret;
  166.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
  167.                 goto erret;
  168.         p->numid = av.intvalue;
  169.  
  170.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_IDS_ids)
  171.                 goto erret;
  172.  
  173.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  174.                 goto erret;
  175.  
  176.         p->ids = (DocUidPtr) MemNew(sizeof(DocUid) * (size_t) p->numid);
  177.         atp = AsnReadId(aip, amp, atp);
  178.  
  179.         for (num = 0; num < p->numid && atp == ENTREZ_IDS_ids_E; num++)
  180.         {
  181.                 if (AsnReadVal(aip, atp, &av) <= 0)
  182.                         goto erret;
  183.                 p->ids[num] = av.intvalue;
  184.                 atp = AsnReadId(aip, amp, atp);
  185.         }
  186.  
  187.         /* check for count mis-match */
  188.         if (num != p->numid || atp != ENTREZ_IDS_ids)
  189.                 goto erret;
  190.  
  191.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  192.                 goto erret;
  193.  
  194.         atp = AsnReadId(aip, amp, atp);
  195.         if (orig == NULL)
  196.         {
  197.                 if (atp != ENTREZ_IDS)
  198.                         goto erret;
  199.         }
  200.         else { /* check for "close struct" associated with "orig" */
  201.                 if (atp != orig)
  202.                         goto erret;
  203.         }
  204.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  205.                 goto erret;
  206.  
  207. ret:
  208.         AsnUnlinkType(orig);
  209.         return p;
  210.  
  211. erret:
  212.         p = EntrezIdsFree(p);
  213.         goto ret;
  214. }
  215.                 
  216.  
  217. Boolean LIBCALL
  218. EntrezIdsAsnWrite (EntrezIdsPtr p, AsnIoPtr aip, AsnTypePtr orig)
  219. {
  220.         DataVal av;
  221.         Int4 i;
  222.         AsnTypePtr atp;
  223.         Boolean retval = FALSE;
  224.  
  225.         if (! NetEntAsnLoad() )
  226.                 return FALSE;
  227.  
  228.         if (aip == NULL)
  229.                 return FALSE;
  230.  
  231.         atp = AsnLinkType(orig, ENTREZ_IDS); /* link local tree */
  232.  
  233.         if (atp == NULL)
  234.                 return FALSE;
  235.  
  236.         if (p == NULL)
  237.         {
  238.                 AsnNullValueMsg(aip, atp);
  239.                 goto erret;
  240.         }
  241.  
  242.  
  243.         if (! AsnStartStruct(aip, atp))
  244.                 goto erret;
  245.         av.intvalue = p->numid;
  246.         AsnWrite (aip, ENTREZ_IDS_numid, &av);
  247.  
  248.         AsnStartStruct (aip, ENTREZ_IDS_ids);
  249.         for (i = 0; i < p->numid; i++)
  250.         {
  251.                 av.intvalue = p->ids[i];
  252.                 AsnWrite (aip, ENTREZ_IDS_ids_E, &av);
  253.         }
  254.         AsnEndStruct (aip, ENTREZ_IDS_ids);
  255.  
  256.         if (! AsnEndStruct(aip, atp) )
  257.                 goto erret;
  258.  
  259.         retval = TRUE;
  260.  
  261. erret:
  262.         AsnUnlinkType(orig); /* unlink local tree */
  263.         return retval;
  264. }
  265.  
  266. /************************** Marked-link-set **********************************/
  267.  
  268. MarkedLinkSetPtr LIBCALL
  269. MarkedLinkSetNew(void)
  270. {
  271.         MarkedLinkSetPtr p;
  272.  
  273.         p = MemNew(sizeof(MarkedLinkSet));
  274.         if (p != NULL)
  275.         {
  276.                 p->link_set = NULL;
  277.                 p->marked_missing = NULL;
  278.         }
  279.         return p;
  280. }
  281.  
  282. MarkedLinkSetPtr LIBCALL
  283. MarkedLinkSetFree(MarkedLinkSetPtr p)
  284. {
  285.         if (p == NULL)
  286.                 return NULL;
  287.         LinkSetFree (p->link_set);
  288.         EntrezIdsFree (p->marked_missing);
  289.  
  290.         return MemFree(p);
  291. }
  292.  
  293. MarkedLinkSetPtr LIBCALL
  294. MarkedLinkSetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  295. {
  296.         DataVal av;
  297.         MarkedLinkSetPtr p;
  298.         EntrezIdsPtr eip;
  299.         LinkSetPtr lsp;
  300.         AsnTypePtr atp;
  301.  
  302.         if (!NetEntAsnLoad())
  303.                 return NULL;
  304.         
  305.         if (aip == NULL)
  306.                 return NULL;
  307.         
  308.         if (orig == NULL)
  309.                 atp = AsnReadId(aip, amp, MARKED_LINK_SET);
  310.         else
  311.                 atp = AsnLinkType(orig, MARKED_LINK_SET); /* link in local tree */
  312.  
  313.         if (atp == NULL)
  314.                 return NULL;
  315.  
  316.         p = MarkedLinkSetNew();
  317.         if (p == NULL)
  318.                 goto erret;
  319.  
  320.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  321.                 goto erret;
  322.  
  323.         if ((atp = AsnReadId(aip, amp, atp)) != MARKED_LINK_SET_link_set)
  324.                 goto erret;
  325.  
  326.         lsp = LinkSetAsnRead(aip, atp);
  327.         if (lsp == NULL)
  328.                 goto erret;
  329.         p->link_set = lsp;
  330.  
  331.         if ((atp = AsnReadId(aip, amp, atp)) != MARKED_LINK_SET_uids_processed)
  332.                 goto erret;
  333.         if (AsnReadVal(aip, atp, &av) <= 0)
  334.                 goto erret;
  335.         p->uids_processed = av.intvalue;
  336.  
  337.         if ((atp = AsnReadId(aip, amp, atp)) == MARKED_LINK_SET_marked_missing)
  338.         { /* optional */
  339.                 eip = EntrezIdsAsnRead(aip, atp);
  340.                 if (eip == NULL)
  341.                         goto erret;
  342.                 p->marked_missing = eip;
  343.                 atp = AsnReadId(aip, amp, atp);
  344.         }
  345.  
  346.         if (orig == NULL)
  347.         {
  348.                 if (atp != MARKED_LINK_SET)
  349.                         goto erret;
  350.         }
  351.         else { /* check for "close struct" associated with "orig" */
  352.                 if (atp != orig)
  353.                         goto erret;
  354.         }
  355.  
  356.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  357.                 goto erret;
  358.  
  359. ret:
  360.         AsnUnlinkType(orig);
  361.         return p;
  362.  
  363. erret:
  364.         p = MarkedLinkSetFree(p);
  365.         goto ret;
  366. }
  367.  
  368. Boolean LIBCALL
  369. MarkedLinkSetAsnWrite (MarkedLinkSetPtr p, AsnIoPtr aip, AsnTypePtr orig)
  370. {
  371.         DataVal av;
  372.         Boolean retval = FALSE;
  373.         AsnTypePtr atp;
  374.  
  375.         if (! NetEntAsnLoad() )
  376.                 return FALSE;
  377.  
  378.         if (aip == NULL)
  379.                 return FALSE;
  380.  
  381.         atp = AsnLinkType(orig, MARKED_LINK_SET); /* link local tree */
  382.  
  383.         if (atp == NULL)
  384.                 return FALSE;
  385.  
  386.         if (p == NULL)
  387.         {
  388.                 AsnNullValueMsg(aip, atp);
  389.                 goto erret;
  390.         }
  391.  
  392.         if (! AsnStartStruct (aip, atp))
  393.                 goto erret;
  394.  
  395.         if (! LinkSetAsnWrite(p->link_set, aip, MARKED_LINK_SET_link_set) )
  396.                 goto erret;
  397.         
  398.         av.intvalue = p->uids_processed;
  399.         AsnWrite(aip, MARKED_LINK_SET_uids_processed, &av);
  400.  
  401.         if (p->marked_missing != NULL) /* optional */
  402.         {
  403.                 if (! EntrezIdsAsnWrite(p->marked_missing, aip, MARKED_LINK_SET_marked_missing) )
  404.                         goto erret;
  405.         }
  406.  
  407.         if (! AsnEndStruct(aip, atp))
  408.                 goto erret;
  409.  
  410.         retval = TRUE;
  411.  
  412. erret:
  413.         AsnUnlinkType(orig); /* unlink local tree */
  414.         return retval;
  415. }
  416.  
  417. /************************** Named-List **********************************/
  418.  
  419. NamedListPtr LIBCALL
  420. NamedListNew(void)
  421. {
  422.         NamedListPtr p;
  423.  
  424.         p = MemNew(sizeof(NamedList));
  425.         p->uids = NULL;
  426.         return p;
  427. }
  428.  
  429. NamedListPtr LIBCALL
  430. NamedListFree(NamedListPtr p)
  431. {
  432.         if (p == NULL)
  433.                 return NULL;
  434.         EntrezIdsFree(p->uids);
  435.  
  436.         return MemFree(p);
  437. }
  438.  
  439. NamedListPtr LIBCALL
  440. NamedListAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  441. {
  442.         DataVal av;
  443.         NamedListPtr p;
  444.         AsnTypePtr atp;
  445.  
  446.         if (!NetEntAsnLoad())
  447.                 return NULL;
  448.         
  449.         if (aip == NULL)
  450.                 return NULL;
  451.         
  452.         if (orig == NULL)
  453.                 atp = AsnReadId(aip, amp, ENTREZ_NAMED_LIST);
  454.         else
  455.                 atp = AsnLinkType(orig, ENTREZ_NAMED_LIST); /* link in local tree */
  456.  
  457.         if (atp == NULL)
  458.                 return NULL;
  459.  
  460.         p = NamedListNew();
  461.         if (p == NULL)
  462.                 goto erret;
  463.  
  464.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  465.                 goto erret;
  466.  
  467.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_NAMED_LIST_term)
  468.                 goto erret;
  469.         if (AsnReadVal(aip, atp, &av) <= 0)
  470.                 goto erret;
  471.         p->term = av.ptrvalue;
  472.  
  473.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_NAMED_LIST_type)
  474.                 goto erret;
  475.         if (AsnReadVal(aip, atp, &av) <= 0)
  476.                 goto erret;
  477.         p->type = av.intvalue;
  478.  
  479.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_NAMED_LIST_fld)
  480.                 goto erret;
  481.         if (AsnReadVal(aip, atp, &av) <= 0)
  482.                 goto erret;
  483.         p->fld = av.intvalue;
  484.  
  485.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_NAMED_LIST_uids)
  486.                 goto erret;
  487.         p->uids = EntrezIdsAsnRead(aip, atp);
  488.         if (p->uids == NULL)
  489.                 goto erret;
  490.  
  491.         atp = AsnReadId(aip, amp, atp);
  492.         if (orig == NULL)
  493.         {
  494.                 if (atp != ENTREZ_NAMED_LIST)
  495.                         goto erret;
  496.         }
  497.         else { /* check for "close struct" associated with "orig" */
  498.                 if (atp != orig)
  499.                         goto erret;
  500.         }
  501.  
  502.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  503.                 goto erret;
  504.  
  505. ret:
  506.         AsnUnlinkType(orig);
  507.         return p;
  508.  
  509. erret:
  510.         p = NamedListFree(p);
  511.         goto ret;
  512. }
  513.  
  514. Boolean LIBCALL
  515. NamedListAsnWrite (NamedListPtr p, AsnIoPtr aip, AsnTypePtr orig)
  516. {
  517.         DataVal av;
  518.         Boolean retval = FALSE;
  519.         AsnTypePtr atp;
  520.  
  521.         if (! NetEntAsnLoad() )
  522.                 return FALSE;
  523.  
  524.         if (aip == NULL)
  525.                 return FALSE;
  526.  
  527.         atp = AsnLinkType(orig, ENTREZ_NAMED_LIST); /* link local tree */
  528.  
  529.         if (atp == NULL)
  530.                 return FALSE;
  531.  
  532.         if (p == NULL)
  533.         {
  534.                 AsnNullValueMsg(aip, atp);
  535.                 goto erret;
  536.         }
  537.  
  538.         if (! AsnStartStruct(aip, atp))
  539.                 goto erret;
  540.  
  541.         av.ptrvalue = p->term;
  542.         AsnWrite (aip, ENTREZ_NAMED_LIST_term, &av);
  543.         av.intvalue = p->type;
  544.         AsnWrite (aip, ENTREZ_NAMED_LIST_type, &av);
  545.         av.intvalue = p->fld;
  546.         AsnWrite (aip, ENTREZ_NAMED_LIST_fld, &av);
  547.     if (! EntrezIdsAsnWrite(p->uids, aip, ENTREZ_NAMED_LIST_uids) )
  548.                 goto erret;
  549.  
  550.         if (! AsnEndStruct(aip, atp))
  551.                 goto erret;
  552.  
  553.         retval = TRUE;
  554.  
  555. erret:
  556.         AsnUnlinkType(orig); /* unlink local tree */
  557.         return retval;
  558. }
  559.  
  560. /************************** Term-by-page **********************************/
  561.  
  562. TermByPagePtr LIBCALL
  563. TermByPageNew(void)
  564. {
  565.         TermByPagePtr p;
  566.  
  567.         p = MemNew(sizeof(TermByPage));
  568.         return p;
  569. }
  570.  
  571. TermByPagePtr LIBCALL
  572. TermByPageFree(TermByPagePtr p)
  573. {
  574.         if (p == NULL)
  575.                 return NULL;
  576.  
  577.         return MemFree(p);
  578. }
  579.  
  580. TermByPagePtr LIBCALL
  581. TermByPageAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  582. {
  583.         DataVal av;
  584.         TermByPagePtr p;
  585.         AsnTypePtr atp;
  586.  
  587.         if (!NetEntAsnLoad())
  588.                 return NULL;
  589.         
  590.         if (aip == NULL)
  591.                 return NULL;
  592.         
  593.         if (orig == NULL)
  594.                 atp = AsnReadId(aip, amp, ENTREZ_TERM_BY_PAGE);
  595.         else
  596.                 atp = AsnLinkType(orig, ENTREZ_TERM_BY_PAGE); /* link in local tree */
  597.  
  598.         if (atp == NULL)
  599.                 return NULL;
  600.  
  601.         p = TermByPageNew();
  602.         if (p == NULL)
  603.                 goto erret;
  604.  
  605.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  606.                 goto erret;
  607.  
  608.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_TERM_BY_PAGE_type)
  609.                 goto erret;
  610.         if (AsnReadVal(aip, atp, &av) <= 0)
  611.                 goto erret;
  612.         p->type = av.intvalue;
  613.  
  614.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_TERM_BY_PAGE_fld)
  615.                 goto erret;
  616.         if (AsnReadVal(aip, atp, &av) <= 0)
  617.                 goto erret;
  618.         p->fld = av.intvalue;
  619.  
  620.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_TERM_BY_PAGE_page)
  621.                 goto erret;
  622.         if (AsnReadVal(aip, atp, &av) <= 0)
  623.                 goto erret;
  624.         p->page = av.intvalue;
  625.  
  626.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_TERM_BY_PAGE_num_pages)
  627.                 goto erret;
  628.         if (AsnReadVal(aip, atp, &av) <= 0)
  629.                 goto erret;
  630.         p->num_pages = av.intvalue;
  631.  
  632.         atp = AsnReadId(aip, amp, atp);
  633.         if (orig == NULL)
  634.         {
  635.                 if (atp != ENTREZ_TERM_BY_PAGE)
  636.                         goto erret;
  637.         }
  638.         else { /* check for "close struct" associated with "orig" */
  639.                 if (atp != orig)
  640.                         goto erret;
  641.         }
  642.  
  643.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  644.                 goto erret;
  645.  
  646. ret:
  647.         AsnUnlinkType(orig);
  648.         return p;
  649.  
  650. erret:
  651.         p = TermByPageFree(p);
  652.         goto ret;
  653. }
  654.  
  655. Boolean LIBCALL
  656. TermByPageAsnWrite (TermByPagePtr p, AsnIoPtr aip, AsnTypePtr orig)
  657. {
  658.         DataVal av;
  659.         Boolean retval = FALSE;
  660.         AsnTypePtr atp;
  661.  
  662.         if (! NetEntAsnLoad() )
  663.                 return FALSE;
  664.  
  665.         if (aip == NULL)
  666.                 return FALSE;
  667.  
  668.         atp = AsnLinkType(orig, ENTREZ_TERM_BY_PAGE); /* link local tree */
  669.  
  670.         if (atp == NULL)
  671.                 return FALSE;
  672.  
  673.         if (p == NULL)
  674.         {
  675.                 AsnNullValueMsg(aip, atp);
  676.                 goto erret;
  677.         }
  678.  
  679.         if (! AsnStartStruct(aip, atp))
  680.                 goto erret;
  681.  
  682.         av.intvalue = p->type;
  683.         AsnWrite (aip, ENTREZ_TERM_BY_PAGE_type, &av);
  684.         av.intvalue = p->fld;
  685.         AsnWrite (aip, ENTREZ_TERM_BY_PAGE_fld, &av);
  686.         av.intvalue = p->page;
  687.         AsnWrite (aip, ENTREZ_TERM_BY_PAGE_page, &av);
  688.         av.intvalue = p->num_pages;
  689.         AsnWrite (aip, ENTREZ_TERM_BY_PAGE_num_pages, &av);
  690.  
  691.         if (! AsnEndStruct(aip, atp))
  692.                 goto erret;
  693.  
  694.         retval = TRUE;
  695.  
  696. erret:
  697.         AsnUnlinkType(orig); /* unlink local tree */
  698.         return retval;
  699. }
  700.  
  701. /************************** Term-by-term **********************************/
  702.  
  703. TermByTermPtr LIBCALL
  704. TermByTermNew(void)
  705. {
  706.         TermByTermPtr p;
  707.  
  708.         p = MemNew(sizeof(TermByTerm));
  709.         p->term = NULL;
  710.         return p;
  711. }
  712.  
  713. TermByTermPtr LIBCALL
  714. TermByTermFree(TermByTermPtr p)
  715. {
  716.         if (p == NULL)
  717.                 return NULL;
  718.         MemFree (p->term);
  719.  
  720.         return MemFree(p);
  721. }
  722.  
  723. TermByTermPtr LIBCALL
  724. TermByTermAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  725. {
  726.         DataVal av;
  727.         TermByTermPtr p;
  728.         AsnTypePtr atp;
  729.  
  730.         if (!NetEntAsnLoad())
  731.                 return NULL;
  732.         
  733.         if (aip == NULL)
  734.                 return NULL;
  735.         
  736.         if (orig == NULL)
  737.                 atp = AsnReadId(aip, amp, ENTREZ_TERM_BY_TERM);
  738.         else
  739.                 atp = AsnLinkType(orig, ENTREZ_TERM_BY_TERM); /* link in local tree */
  740.  
  741.         if (atp == NULL)
  742.                 return NULL;
  743.  
  744.         p = TermByTermNew();
  745.         if (p == NULL)
  746.                 goto erret;
  747.  
  748.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  749.                 goto erret;
  750.  
  751.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_TERM_BY_TERM_type)
  752.                 goto erret;
  753.         if (AsnReadVal(aip, atp, &av) <= 0)
  754.                 goto erret;
  755.         p->type = av.intvalue;
  756.  
  757.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_TERM_BY_TERM_fld)
  758.                 goto erret;
  759.         if (AsnReadVal(aip, atp, &av) <= 0)
  760.                 goto erret;
  761.         p->fld = av.intvalue;
  762.  
  763.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_TERM_BY_TERM_term)
  764.                 goto erret;
  765.         if (AsnReadVal(aip, atp, &av) <= 0)
  766.                 goto erret;
  767.         p->term = av.ptrvalue;
  768.  
  769.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_TERM_BY_TERM_num_terms)
  770.                 goto erret;
  771.         if (AsnReadVal(aip, atp, &av) <= 0)
  772.                 goto erret;
  773.         p->num_terms = av.intvalue;
  774.  
  775.         atp = AsnReadId(aip, amp, atp);
  776.         if (orig == NULL)
  777.         {
  778.                 if (atp != ENTREZ_TERM_BY_TERM)
  779.                         goto erret;
  780.         }
  781.         else { /* check for "close struct" associated with "orig" */
  782.                 if (atp != orig)
  783.                         goto erret;
  784.         }
  785.  
  786.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  787.                 goto erret;
  788.  
  789. ret:
  790.         AsnUnlinkType(orig);
  791.         return p;
  792.  
  793. erret:
  794.         p = TermByTermFree(p);
  795.         goto ret;
  796. }
  797.  
  798. Boolean LIBCALL
  799. TermByTermAsnWrite (TermByTermPtr p, AsnIoPtr aip, AsnTypePtr orig)
  800. {
  801.         DataVal av;
  802.         Boolean retval = FALSE;
  803.         AsnTypePtr atp;
  804.  
  805.         if (! NetEntAsnLoad() )
  806.                 return FALSE;
  807.  
  808.         if (aip == NULL)
  809.                 return FALSE;
  810.  
  811.         atp = AsnLinkType(orig, ENTREZ_TERM_BY_TERM); /* link local tree */
  812.  
  813.         if (atp == NULL)
  814.                 return FALSE;
  815.  
  816.         if (p == NULL)
  817.         {
  818.                 AsnNullValueMsg(aip, atp);
  819.                 goto erret;
  820.         }
  821.  
  822.         if (! AsnStartStruct(aip, atp))
  823.                 goto erret;
  824.  
  825.         av.intvalue = p->type;
  826.         AsnWrite (aip, ENTREZ_TERM_BY_TERM_type, &av);
  827.         av.intvalue = p->fld;
  828.         AsnWrite (aip, ENTREZ_TERM_BY_TERM_fld, &av);
  829.         av.ptrvalue = p->term;
  830.         AsnWrite (aip, ENTREZ_TERM_BY_TERM_term, &av);
  831.         av.intvalue = p->num_terms;
  832.         AsnWrite (aip, ENTREZ_TERM_BY_TERM_num_terms, &av);
  833.  
  834.         if (! AsnEndStruct(aip, atp))
  835.                 goto erret;
  836.  
  837.         retval = TRUE;
  838.  
  839. erret:
  840.         AsnUnlinkType(orig); /* unlink local tree */
  841.         return retval;
  842. }
  843.  
  844. /************************** Term-Lookup **********************************/
  845.  
  846. TermLookupPtr LIBCALL
  847. TermLookupNew(void)
  848. {
  849.         TermLookupPtr p;
  850.  
  851.         p = MemNew(sizeof(TermLookup));
  852.         p->term = NULL;
  853.         return p;
  854. }
  855.  
  856. TermLookupPtr LIBCALL
  857. TermLookupFree(TermLookupPtr p)
  858. {
  859.         if (p == NULL)
  860.                 return NULL;
  861.         MemFree (p->term);
  862.  
  863.         return MemFree(p);
  864. }
  865.  
  866. TermLookupPtr LIBCALL
  867. TermLookupAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  868. {
  869.         DataVal av;
  870.         TermLookupPtr p;
  871.         AsnTypePtr atp;
  872.  
  873.         if (!NetEntAsnLoad())
  874.                 return NULL;
  875.         
  876.         if (aip == NULL)
  877.                 return NULL;
  878.         
  879.         if (orig == NULL)
  880.                 atp = AsnReadId(aip, amp, TERM_LOOKUP);
  881.         else
  882.                 atp = AsnLinkType(orig, TERM_LOOKUP); /* link in local tree */
  883.  
  884.         if (atp == NULL)
  885.                 return NULL;
  886.  
  887.         p = TermLookupNew();
  888.         if (p == NULL)
  889.                 goto erret;
  890.  
  891.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  892.                 goto erret;
  893.  
  894.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_LOOKUP_type)
  895.                 goto erret;
  896.         if (AsnReadVal(aip, atp, &av) <= 0)
  897.                 goto erret;
  898.         p->type = av.intvalue;
  899.  
  900.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_LOOKUP_fld)
  901.                 goto erret;
  902.         if (AsnReadVal(aip, atp, &av) <= 0)
  903.                 goto erret;
  904.         p->fld = av.intvalue;
  905.  
  906.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_LOOKUP_term)
  907.                 goto erret;
  908.         if (AsnReadVal(aip, atp, &av) <= 0)
  909.                 goto erret;
  910.         p->term = av.ptrvalue;
  911.  
  912.         atp = AsnReadId(aip, amp, atp);
  913.         if (orig == NULL)
  914.         {
  915.                 if (atp != TERM_LOOKUP)
  916.                         goto erret;
  917.         }
  918.         else { /* check for "close struct" associated with "orig" */
  919.                 if (atp != orig)
  920.                         goto erret;
  921.         }
  922.  
  923.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  924.                 goto erret;
  925.  
  926. ret:
  927.         AsnUnlinkType(orig);
  928.         return p;
  929.  
  930. erret:
  931.         p = TermLookupFree(p);
  932.         goto ret;
  933. }
  934.  
  935. Boolean LIBCALL
  936. TermLookupAsnWrite (TermLookupPtr p, AsnIoPtr aip, AsnTypePtr orig)
  937. {
  938.         DataVal av;
  939.         Boolean retval = FALSE;
  940.         AsnTypePtr atp;
  941.  
  942.         if (! NetEntAsnLoad() )
  943.                 return FALSE;
  944.  
  945.         if (aip == NULL)
  946.                 return FALSE;
  947.  
  948.         atp = AsnLinkType(orig, TERM_LOOKUP); /* link local tree */
  949.  
  950.         if (atp == NULL)
  951.                 return FALSE;
  952.  
  953.         if (p == NULL)
  954.         {
  955.                 AsnNullValueMsg(aip, atp);
  956.                 goto erret;
  957.         }
  958.  
  959.         if (! AsnStartStruct(aip, atp))
  960.                 goto erret;
  961.  
  962.         av.intvalue = p->type;
  963.         AsnWrite (aip, TERM_LOOKUP_type, &av);
  964.         av.intvalue = p->fld;
  965.         AsnWrite (aip, TERM_LOOKUP_fld, &av);
  966.         av.ptrvalue = p->term;
  967.         AsnWrite (aip, TERM_LOOKUP_term, &av);
  968.  
  969.         if (! AsnEndStruct(aip, atp))
  970.                 goto erret;
  971.  
  972.         retval = TRUE;
  973.  
  974. erret:
  975.         AsnUnlinkType(orig); /* unlink local tree */
  976.         return retval;
  977. }
  978.  
  979. /************************** Term-Page-Info **********************************/
  980.  
  981. TermPageInfoPtr LIBCALL
  982. TermPageInfoNew(void)
  983. {
  984.         TermPageInfoPtr p;
  985.  
  986.         p = MemNew(sizeof(TermPageInfo));
  987.         p->term = NULL;
  988.         return p;
  989. }
  990.  
  991. TermPageInfoPtr LIBCALL
  992. TermPageInfoFree(TermPageInfoPtr p)
  993. {
  994.         if (p == NULL)
  995.                 return NULL;
  996.         MemFree (p->term);
  997.  
  998.         return MemFree(p);
  999. }
  1000.  
  1001. TermPageInfoPtr LIBCALL
  1002. TermPageInfoAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  1003. {
  1004.         DataVal av;
  1005.         TermPageInfoPtr p;
  1006.         AsnTypePtr atp;
  1007.  
  1008.         if (!NetEntAsnLoad())
  1009.                 return NULL;
  1010.         
  1011.         if (aip == NULL)
  1012.                 return NULL;
  1013.         
  1014.         if (orig == NULL)
  1015.                 atp = AsnReadId(aip, amp, TERM_PAGE_INFO);
  1016.         else
  1017.                 atp = AsnLinkType(orig, TERM_PAGE_INFO); /* link in local tree */
  1018.  
  1019.         if (atp == NULL)
  1020.                 return NULL;
  1021.  
  1022.         p = TermPageInfoNew();
  1023.         if (p == NULL)
  1024.                 goto erret;
  1025.  
  1026.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  1027.                 goto erret;
  1028.  
  1029.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_PAGE_INFO_term)
  1030.                 goto erret;
  1031.         if (AsnReadVal(aip, atp, &av) <= 0)
  1032.                 goto erret;
  1033.         p->term = av.ptrvalue;
  1034.  
  1035.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_PAGE_INFO_spec_count)
  1036.                 goto erret;
  1037.         if (AsnReadVal(aip, atp, &av) <= 0)
  1038.                 goto erret;
  1039.         p->spec_count = av.intvalue;
  1040.  
  1041.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_PAGE_INFO_tot_count)
  1042.                 goto erret;
  1043.         if (AsnReadVal(aip, atp, &av) <= 0)
  1044.                 goto erret;
  1045.         p->tot_count = av.intvalue;
  1046.  
  1047.         atp = AsnReadId(aip, amp, atp);
  1048.         if (orig == NULL)
  1049.         {
  1050.                 if (atp != TERM_PAGE_INFO)
  1051.                         goto erret;
  1052.         }
  1053.         else { /* check for "close struct" associated with "orig" */
  1054.                 if (atp != orig)
  1055.                         goto erret;
  1056.         }
  1057.  
  1058.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  1059.                 goto erret;
  1060.  
  1061. ret:
  1062.         AsnUnlinkType(orig);
  1063.         return p;
  1064.  
  1065. erret:
  1066.         p = TermPageInfoFree(p);
  1067.         goto ret;
  1068. }
  1069.  
  1070. Boolean LIBCALL
  1071. TermPageInfoAsnWrite (TermPageInfoPtr p, AsnIoPtr aip, AsnTypePtr orig)
  1072. {
  1073.         DataVal av;
  1074.         Boolean retval = FALSE;
  1075.         AsnTypePtr atp;
  1076.  
  1077.         if (! NetEntAsnLoad() )
  1078.                 return FALSE;
  1079.  
  1080.         if (aip == NULL)
  1081.                 return FALSE;
  1082.  
  1083.         atp = AsnLinkType(orig, TERM_PAGE_INFO); /* link local tree */
  1084.  
  1085.         if (atp == NULL)
  1086.                 return FALSE;
  1087.  
  1088.         if (p == NULL)
  1089.         {
  1090.                 AsnNullValueMsg(aip, atp);
  1091.                 goto erret;
  1092.         }
  1093.  
  1094.         if (! AsnStartStruct(aip, atp))
  1095.                 goto erret;
  1096.  
  1097.         av.ptrvalue = p->term;
  1098.         AsnWrite (aip, TERM_PAGE_INFO_term, &av);
  1099.         av.intvalue = p->spec_count;
  1100.         AsnWrite (aip, TERM_PAGE_INFO_spec_count, &av);
  1101.         av.intvalue = p->tot_count;
  1102.         AsnWrite (aip, TERM_PAGE_INFO_tot_count, &av);
  1103.  
  1104.         if (! AsnEndStruct(aip, atp))
  1105.                 goto erret;
  1106.  
  1107.         retval = TRUE;
  1108.  
  1109. erret:
  1110.         AsnUnlinkType(orig); /* unlink local tree */
  1111.         return retval;
  1112. }
  1113.  
  1114. /************************** Term-Counts **********************************/
  1115.  
  1116. TermCountsPtr LIBCALL
  1117. TermCountsNew(void)
  1118. {
  1119.         TermCountsPtr p;
  1120.  
  1121.         p = MemNew(sizeof(TermCounts));
  1122.         return p;
  1123. }
  1124.  
  1125. TermCountsPtr LIBCALL
  1126. TermCountsFree(TermCountsPtr p)
  1127. {
  1128.         if (p == NULL)
  1129.                 return NULL;
  1130.  
  1131.         return MemFree(p);
  1132. }
  1133.  
  1134. TermCountsPtr LIBCALL
  1135. TermCountsAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  1136. {
  1137.         DataVal av;
  1138.         TermCountsPtr p;
  1139.         AsnTypePtr atp;
  1140.  
  1141.         if (!NetEntAsnLoad())
  1142.                 return NULL;
  1143.         
  1144.         if (aip == NULL)
  1145.                 return NULL;
  1146.         
  1147.         if (orig == NULL)
  1148.                 atp = AsnReadId(aip, amp, TERM_COUNTS);
  1149.         else
  1150.                 atp = AsnLinkType(orig, TERM_COUNTS); /* link in local tree */
  1151.  
  1152.         if (atp == NULL)
  1153.                 return NULL;
  1154.  
  1155.         p = TermCountsNew();
  1156.         if (p == NULL)
  1157.                 goto erret;
  1158.  
  1159.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  1160.                 goto erret;
  1161.  
  1162.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_COUNTS_found)
  1163.                 goto erret;
  1164.         if (AsnReadVal(aip, atp, &av) <= 0)
  1165.                 goto erret;
  1166.         p->found = av.boolvalue;
  1167.  
  1168.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_COUNTS_spec_count)
  1169.                 goto erret;
  1170.         if (AsnReadVal(aip, atp, &av) <= 0)
  1171.                 goto erret;
  1172.         p->spec_count = av.intvalue;
  1173.  
  1174.         if ((atp = AsnReadId(aip, amp, atp)) != TERM_COUNTS_tot_count)
  1175.                 goto erret;
  1176.         if (AsnReadVal(aip, atp, &av) <= 0)
  1177.                 goto erret;
  1178.         p->tot_count = av.intvalue;
  1179.  
  1180.         atp = AsnReadId(aip, amp, atp);
  1181.         if (orig == NULL)
  1182.         {
  1183.                 if (atp != TERM_COUNTS)
  1184.                         goto erret;
  1185.         }
  1186.         else { /* check for "close struct" associated with "orig" */
  1187.                 if (atp != orig)
  1188.                         goto erret;
  1189.         }
  1190.  
  1191.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  1192.                 goto erret;
  1193.  
  1194. ret:
  1195.         AsnUnlinkType(orig);
  1196.         return p;
  1197.  
  1198. erret:
  1199.         p = TermCountsFree(p);
  1200.         goto ret;
  1201. }
  1202.  
  1203. Boolean LIBCALL
  1204. TermCountsAsnWrite (TermCountsPtr p, AsnIoPtr aip, AsnTypePtr orig)
  1205. {
  1206.         DataVal av;
  1207.         Boolean retval = FALSE;
  1208.         AsnTypePtr atp;
  1209.  
  1210.         if (! NetEntAsnLoad() )
  1211.                 return FALSE;
  1212.  
  1213.         if (aip == NULL)
  1214.                 return FALSE;
  1215.  
  1216.         atp = AsnLinkType(orig, TERM_COUNTS); /* link local tree */
  1217.  
  1218.         if (atp == NULL)
  1219.                 return FALSE;
  1220.  
  1221.         if (p == NULL)
  1222.         {
  1223.                 AsnNullValueMsg(aip, atp);
  1224.                 goto erret;
  1225.         }
  1226.  
  1227.         if (! AsnStartStruct(aip, atp))
  1228.                 goto erret;
  1229.  
  1230.         av.boolvalue = p->found;
  1231.         AsnWrite (aip, TERM_COUNTS_found, &av);
  1232.         av.intvalue = p->spec_count;
  1233.         AsnWrite (aip, TERM_COUNTS_spec_count, &av);
  1234.         av.intvalue = p->tot_count;
  1235.         AsnWrite (aip, TERM_COUNTS_tot_count, &av);
  1236.  
  1237.         if (! AsnEndStruct(aip, atp))
  1238.                 goto erret;
  1239.  
  1240.         retval = TRUE;
  1241.  
  1242. erret:
  1243.         AsnUnlinkType(orig); /* unlink local tree */
  1244.         return retval;
  1245. }
  1246.  
  1247. /************************** LinkSetGet ****************************************/
  1248.  
  1249. LinkSetGetPtr LIBCALL
  1250. LinkSetGetNew(void)
  1251. {
  1252.         LinkSetGetPtr p;
  1253.  
  1254.         p = MemNew(sizeof(LinkSetGet));
  1255.         if (p != NULL)
  1256.         {
  1257.                 p->query_size = 0;
  1258.                 p->query = NULL;
  1259.         }
  1260.         return p;
  1261. }
  1262.  
  1263. LinkSetGetPtr LIBCALL
  1264. LinkSetGetFree(LinkSetGetPtr p)
  1265. {
  1266.         if (p == NULL)
  1267.                 return NULL;
  1268.         MemFree (p->query);
  1269.         return MemFree(p);
  1270. }
  1271.                 
  1272. LinkSetGetPtr LIBCALL
  1273. LinkSetGetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  1274. {
  1275.         DataVal av;
  1276.         LinkSetGetPtr p;
  1277.         AsnTypePtr atp;
  1278.         Int4 num;
  1279.  
  1280.         if (!NetEntAsnLoad())
  1281.                 return NULL;
  1282.         
  1283.         if (aip == NULL)
  1284.                 return NULL;
  1285.         
  1286.         if (orig == NULL)
  1287.                 atp = AsnReadId(aip, amp, LINK_SETGET);
  1288.         else
  1289.                 atp = AsnLinkType(orig, LINK_SETGET); /* link in local tree */
  1290.  
  1291.         if (atp == NULL)
  1292.                 return NULL;
  1293.  
  1294.         p = LinkSetGetNew();
  1295.         if (p == NULL)
  1296.                 goto erret;
  1297.  
  1298.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  1299.                 goto erret;
  1300.  
  1301.         atp = AsnReadId(aip, amp, atp); /* find the num */
  1302.         if (atp == NULL)
  1303.                 goto erret;
  1304.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
  1305.                 goto erret;
  1306.         p->max = av.intvalue;
  1307.  
  1308.         atp = AsnReadId(aip, amp, atp);
  1309.         if (atp == NULL)
  1310.                 goto erret;
  1311.         if (AsnReadVal(aip, atp, &av) <= 0)
  1312.                 goto erret;
  1313.         p->link_to_cls = av.intvalue;
  1314.  
  1315.         atp = AsnReadId(aip, amp, atp);
  1316.         if (atp == NULL)
  1317.                 goto erret;
  1318.         if (AsnReadVal(aip, atp, &av) <= 0)
  1319.                 goto erret;
  1320.         p->query_cls = av.intvalue;
  1321.  
  1322.         atp = AsnReadId(aip, amp, atp);
  1323.         if (atp == LINK_SETGET_mark_missing)
  1324.         {
  1325.                 if (AsnReadVal(aip, atp, &av) <= 0)
  1326.                         goto erret;
  1327.                 p->mark_missing = av.boolvalue;
  1328.                 atp = AsnReadId(aip, amp, atp);
  1329.         }
  1330.  
  1331.         if (atp != LINK_SETGET_query_size)
  1332.                 goto erret;
  1333.         if (AsnReadVal(aip, atp, &av) <= 0)
  1334.                 goto erret;
  1335.         p->query_size = av.intvalue;
  1336.  
  1337.         if ((atp = AsnReadId(aip, amp, atp)) != LINK_SETGET_query)
  1338.                 goto erret;
  1339.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  1340.                 goto erret;
  1341.  
  1342.         p->query = (DocUidPtr) MemNew(sizeof(DocUid) * (size_t) p->query_size);
  1343.         atp = AsnReadId(aip, amp, atp);
  1344.  
  1345.         for (num = 0; num < p->query_size && atp == LINK_SETGET_query_E; num++)
  1346.         {
  1347.                 if (AsnReadVal(aip, atp, &av) <= 0)
  1348.                         goto erret;
  1349.                 p->query[num] = av.intvalue;
  1350.                 atp = AsnReadId(aip, amp, atp);
  1351.         }
  1352.  
  1353.         /* check for count mis-match */
  1354.         if (num != p->query_size || atp != LINK_SETGET_query)
  1355.                 goto erret;
  1356.  
  1357.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  1358.                 goto erret;
  1359.  
  1360.         atp = AsnReadId(aip, amp, atp);
  1361.         if (orig == NULL)
  1362.         {
  1363.                 if (atp != LINK_SETGET)
  1364.                         goto erret;
  1365.         }
  1366.         else { /* check for "close struct" associated with "orig" */
  1367.                 if (atp != orig)
  1368.                         goto erret;
  1369.         }
  1370.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  1371.                 goto erret;
  1372.  
  1373. ret:
  1374.         AsnUnlinkType(orig);
  1375.         return p;
  1376.  
  1377. erret:
  1378.         p = LinkSetGetFree(p);
  1379.         goto ret;
  1380. }
  1381.                 
  1382.  
  1383. Boolean LIBCALL
  1384. LinkSetGetAsnWrite (LinkSetGetPtr p, AsnIoPtr aip, AsnTypePtr orig)
  1385. {
  1386.         DataVal av;
  1387.         Int4 i;
  1388.         AsnTypePtr atp;
  1389.         Boolean retval = FALSE;
  1390.  
  1391.         if (! NetEntAsnLoad() )
  1392.                 return FALSE;
  1393.  
  1394.         if (aip == NULL)
  1395.                 return FALSE;
  1396.  
  1397.         atp = AsnLinkType(orig, LINK_SETGET); /* link local tree */
  1398.  
  1399.         if (atp == NULL)
  1400.                 return FALSE;
  1401.  
  1402.         if (p == NULL)
  1403.         {
  1404.                 AsnNullValueMsg(aip, atp);
  1405.                 goto erret;
  1406.         }
  1407.  
  1408.  
  1409.         if (! AsnStartStruct(aip, atp))
  1410.                 goto erret;
  1411.         av.intvalue = p->max;
  1412.         AsnWrite (aip, LINK_SETGET_max, &av);
  1413.         av.intvalue = p->link_to_cls;
  1414.         AsnWrite (aip, LINK_SETGET_link_to_cls, &av);
  1415.         av.intvalue = p->query_cls;
  1416.         AsnWrite (aip, LINK_SETGET_query_cls, &av);
  1417.         av.boolvalue = p->mark_missing;
  1418.         AsnWrite (aip, LINK_SETGET_mark_missing, &av);
  1419.         av.intvalue = p->query_size;
  1420.         AsnWrite (aip, LINK_SETGET_query_size, &av);
  1421.  
  1422.         AsnStartStruct (aip, LINK_SETGET_query);
  1423.         for (i = 0; i < p->query_size; i++)
  1424.         {
  1425.                 av.intvalue = p->query[i];
  1426.                 AsnWrite (aip, LINK_SETGET_query_E, &av);
  1427.         }
  1428.         AsnEndStruct (aip, LINK_SETGET_query);
  1429.  
  1430.         if (! AsnEndStruct(aip, atp))
  1431.                 goto erret;
  1432.  
  1433.         retval = TRUE;
  1434.  
  1435. erret:
  1436.         AsnUnlinkType(orig); /* unlink local tree */
  1437.         return retval;
  1438. }
  1439.  
  1440. /************************** Medline-Summary **********************************/
  1441.  
  1442. DocSumPtr LIBCALL
  1443. MlSumNew(void)
  1444. {
  1445.         DocSumPtr p;
  1446.  
  1447.         p = MemNew(sizeof(DocSum));
  1448.         p->caption = NULL;
  1449.         p->title = NULL;
  1450.         return p;
  1451. }
  1452.  
  1453. DocSumPtr LIBCALL
  1454. MlSumFree(DocSumPtr p)
  1455. {
  1456.         if (p == NULL)
  1457.                 return NULL;
  1458.         MemFree(p->caption);
  1459.         MemFree(p->title);
  1460.  
  1461.         return MemFree(p);
  1462. }
  1463.  
  1464. DocSumPtr LIBCALL
  1465. MlSumAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  1466. {
  1467.         DataVal av;
  1468.         DocSumPtr p;
  1469.         AsnTypePtr atp;
  1470.  
  1471.         if (!NetEntAsnLoad())
  1472.                 return NULL;
  1473.         
  1474.         if (aip == NULL)
  1475.                 return NULL;
  1476.         
  1477.         if (orig == NULL)
  1478.                 atp = AsnReadId(aip, amp, ML_SUMMARY);
  1479.         else
  1480.                 atp = AsnLinkType(orig, ML_SUMMARY); /* link in local tree */
  1481.  
  1482.         if (atp == NULL)
  1483.                 return NULL;
  1484.  
  1485.         p = MlSumNew();
  1486.         if (p == NULL)
  1487.                 goto erret;
  1488.  
  1489.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  1490.                 goto erret;
  1491.  
  1492.         if ((atp = AsnReadId(aip, amp, atp)) != ML_SUMMARY_muid)
  1493.                 goto erret;
  1494.         if (AsnReadVal(aip, atp, &av) <= 0)
  1495.                 goto erret;
  1496.         p->uid = av.intvalue;
  1497.  
  1498.         if ((atp = AsnReadId(aip, amp, atp)) != ML_SUMMARY_no_abstract)
  1499.                 goto erret;
  1500.         if (AsnReadVal(aip, atp, &av) <= 0)
  1501.                 goto erret;
  1502.         p->no_abstract = av.boolvalue;
  1503.  
  1504.         if ((atp = AsnReadId(aip, amp, atp)) != ML_SUMMARY_translated_title)
  1505.                 goto erret;
  1506.         if (AsnReadVal(aip, atp, &av) <= 0)
  1507.                 goto erret;
  1508.         p->translated_title = av.boolvalue;
  1509.  
  1510.         if ((atp = AsnReadId(aip, amp, atp)) != ML_SUMMARY_no_authors)
  1511.                 goto erret;
  1512.         if (AsnReadVal(aip, atp, &av) <= 0)
  1513.                 goto erret;
  1514.         p->no_authors = av.boolvalue;
  1515.  
  1516.         atp = AsnReadId(aip, amp, atp);
  1517.         if (atp == ML_SUMMARY_caption)
  1518.         {
  1519.                 if (AsnReadVal(aip, atp, &av) <= 0)
  1520.                         goto erret;
  1521.                 p->caption = av.ptrvalue;
  1522.                 atp = AsnReadId(aip, amp, atp);
  1523.         }
  1524.  
  1525.         if (atp == ML_SUMMARY_title)
  1526.         {
  1527.                 if (AsnReadVal(aip, atp, &av) <= 0)
  1528.                         goto erret;
  1529.                 p->title = av.ptrvalue;
  1530.                 atp = AsnReadId(aip, amp, atp);
  1531.         }
  1532.  
  1533.         if (orig == NULL)
  1534.         {
  1535.                 if (atp != ML_SUMMARY)
  1536.                         goto erret;
  1537.         }
  1538.         else { /* check for "close struct" associated with "orig" */
  1539.                 if (atp != orig)
  1540.                         goto erret;
  1541.         }
  1542.  
  1543.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  1544.                 goto erret;
  1545.  
  1546. ret:
  1547.         AsnUnlinkType(orig);
  1548.         return p;
  1549.  
  1550. erret:
  1551.         p = DocSumFree(p);
  1552.         goto ret;
  1553. }
  1554.  
  1555. Boolean LIBCALL
  1556. MlSumAsnWrite (DocSumPtr p, AsnIoPtr aip, AsnTypePtr orig)
  1557. {
  1558.         DataVal av;
  1559.         Boolean retval = FALSE;
  1560.         AsnTypePtr atp;
  1561.  
  1562.         if (! NetEntAsnLoad() )
  1563.                 return FALSE;
  1564.  
  1565.         if (aip == NULL)
  1566.                 return FALSE;
  1567.  
  1568.         atp = AsnLinkType(orig, ML_SUMMARY); /* link local tree */
  1569.  
  1570.         if (atp == NULL)
  1571.                 return FALSE;
  1572.  
  1573.         if (p == NULL)
  1574.         {
  1575.                 AsnNullValueMsg(aip, atp);
  1576.                 goto erret;
  1577.         }
  1578.  
  1579.         if (! AsnStartStruct(aip, atp))
  1580.                 goto erret;
  1581.  
  1582.         av.intvalue = p->uid;
  1583.         AsnWrite (aip, ML_SUMMARY_muid, &av);
  1584.         av.boolvalue = p->no_abstract;
  1585.         AsnWrite (aip, ML_SUMMARY_no_abstract, &av);
  1586.         av.boolvalue = p->translated_title;
  1587.         AsnWrite (aip, ML_SUMMARY_translated_title, &av);
  1588.         av.boolvalue = p->no_authors;
  1589.         AsnWrite (aip, ML_SUMMARY_no_authors, &av);
  1590.         if (p->caption != NULL)
  1591.         {
  1592.                 av.ptrvalue = p->caption;
  1593.                 AsnWrite (aip, ML_SUMMARY_caption, &av);
  1594.         }
  1595.         if (p->title != NULL)
  1596.         {
  1597.                 av.ptrvalue = p->title;
  1598.                 AsnWrite (aip, ML_SUMMARY_title, &av);
  1599.         }
  1600.  
  1601.         if (! AsnEndStruct(aip, atp))
  1602.                 goto erret;
  1603.  
  1604.         retval = TRUE;
  1605.  
  1606. erret:
  1607.         AsnUnlinkType(orig); /* unlink local tree */
  1608.         return retval;
  1609. }
  1610.  
  1611. /************************** Sequence-Summary **********************************/
  1612.  
  1613. DocSumPtr LIBCALL
  1614. SeqSumNew(void)
  1615. {
  1616.         DocSumPtr p;
  1617.  
  1618.         p = MemNew(sizeof(DocSum));
  1619.         p->caption = NULL;
  1620.         p->title = NULL;
  1621.         return p;
  1622. }
  1623.  
  1624. DocSumPtr LIBCALL
  1625. SeqSumFree(DocSumPtr p)
  1626. {
  1627.         if (p == NULL)
  1628.                 return NULL;
  1629.         MemFree(p->caption);
  1630.         MemFree(p->title);
  1631.  
  1632.         return MemFree(p);
  1633. }
  1634.  
  1635. DocSumPtr LIBCALL
  1636. SeqSumAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  1637. {
  1638.         DataVal av;
  1639.         DocSumPtr p;
  1640.         AsnTypePtr atp;
  1641.  
  1642.         if (!NetEntAsnLoad())
  1643.                 return NULL;
  1644.         
  1645.         if (aip == NULL)
  1646.                 return NULL;
  1647.         
  1648.         if (orig == NULL)
  1649.                 atp = AsnReadId(aip, amp, SEQ_SUMMARY);
  1650.         else
  1651.                 atp = AsnLinkType(orig, SEQ_SUMMARY); /* link in local tree */
  1652.  
  1653.         if (atp == NULL)
  1654.                 return NULL;
  1655.  
  1656.         p = SeqSumNew();
  1657.         if (p == NULL)
  1658.                 goto erret;
  1659.  
  1660.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  1661.                 goto erret;
  1662.  
  1663.         if ((atp = AsnReadId(aip, amp, atp)) != SEQ_SUMMARY_id)
  1664.                 goto erret;
  1665.         if (AsnReadVal(aip, atp, &av) <= 0)
  1666.                 goto erret;
  1667.         p->uid = av.intvalue;
  1668.  
  1669.         atp = AsnReadId(aip, amp, atp);
  1670.         if (atp == SEQ_SUMMARY_caption)
  1671.         {
  1672.                 if (AsnReadVal(aip, atp, &av) <= 0)
  1673.                         goto erret;
  1674.                 p->caption = av.ptrvalue;
  1675.                 atp = AsnReadId(aip, amp, atp);
  1676.         }
  1677.  
  1678.         if (atp == SEQ_SUMMARY_title)
  1679.         {
  1680.                 if (AsnReadVal(aip, atp, &av) <= 0)
  1681.                         goto erret;
  1682.                 p->title = av.ptrvalue;
  1683.                 atp = AsnReadId(aip, amp, atp);
  1684.         }
  1685.  
  1686.         if (orig == NULL)
  1687.         {
  1688.                 if (atp != SEQ_SUMMARY)
  1689.                         goto erret;
  1690.         }
  1691.         else { /* check for "close struct" associated with "orig" */
  1692.                 if (atp != orig)
  1693.                         goto erret;
  1694.         }
  1695.  
  1696.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  1697.                 goto erret;
  1698.  
  1699. ret:
  1700.         AsnUnlinkType(orig);
  1701.         return p;
  1702.  
  1703. erret:
  1704.         p = DocSumFree(p);
  1705.         goto ret;
  1706. }
  1707.  
  1708. Boolean LIBCALL
  1709. SeqSumAsnWrite (DocSumPtr p, AsnIoPtr aip, AsnTypePtr orig)
  1710. {
  1711.         DataVal av;
  1712.         Boolean retval = FALSE;
  1713.         AsnTypePtr atp;
  1714.  
  1715.         if (! NetEntAsnLoad() )
  1716.                 return FALSE;
  1717.  
  1718.         if (aip == NULL)
  1719.                 return FALSE;
  1720.  
  1721.         atp = AsnLinkType(orig, SEQ_SUMMARY); /* link local tree */
  1722.  
  1723.         if (atp == NULL)
  1724.                 return FALSE;
  1725.  
  1726.         if (p == NULL)
  1727.         {
  1728.                 AsnNullValueMsg(aip, atp);
  1729.                 goto erret;
  1730.         }
  1731.  
  1732.         if (! AsnStartStruct(aip, atp))
  1733.                 goto erret;
  1734.  
  1735.         av.intvalue = p->uid;
  1736.         AsnWrite (aip, SEQ_SUMMARY_id, &av);
  1737.         if (p->caption != NULL)
  1738.         {
  1739.                 av.ptrvalue = p->caption;
  1740.                 AsnWrite (aip, SEQ_SUMMARY_caption, &av);
  1741.         }
  1742.         if (p->title != NULL)
  1743.         {
  1744.                 av.ptrvalue = p->title;
  1745.                 AsnWrite (aip, SEQ_SUMMARY_title, &av);
  1746.         }
  1747.  
  1748.         if (! AsnEndStruct(aip, atp))
  1749.                 goto erret;
  1750.  
  1751.         retval = TRUE;
  1752.  
  1753. erret:
  1754.         AsnUnlinkType(orig); /* unlink local tree */
  1755.         return retval;
  1756. }
  1757.  
  1758. /************************** Entrez-DocGet **********************************/
  1759.  
  1760. EntrezDocGetPtr LIBCALL
  1761. EntrezDocGetNew(void)
  1762. {
  1763.         EntrezDocGetPtr p;
  1764.  
  1765.         p = MemNew(sizeof(EntrezDocGet));
  1766.         p->ids = NULL;
  1767.         p->defer_count = 0;
  1768.         return p;
  1769. }
  1770.  
  1771. EntrezDocGetPtr LIBCALL
  1772. EntrezDocGetFree(EntrezDocGetPtr p)
  1773. {
  1774.         if (p == NULL)
  1775.                 return NULL;
  1776.         EntrezIdsFree(p->ids);
  1777.  
  1778.         return MemFree(p);
  1779. }
  1780.  
  1781. EntrezDocGetPtr LIBCALL
  1782. EntrezDocGetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  1783. {
  1784.         DataVal av;
  1785.         EntrezDocGetPtr p;
  1786.         AsnTypePtr atp;
  1787.  
  1788.         if (!NetEntAsnLoad())
  1789.                 return NULL;
  1790.         
  1791.         if (aip == NULL)
  1792.                 return NULL;
  1793.         
  1794.         if (orig == NULL)
  1795.                 atp = AsnReadId(aip, amp, ENTREZ_DOCGET);
  1796.         else
  1797.                 atp = AsnLinkType(orig, ENTREZ_DOCGET); /* link in local tree */
  1798.  
  1799.         if (atp == NULL)
  1800.                 return NULL;
  1801.  
  1802.         p = EntrezDocGetNew();
  1803.         if (p == NULL)
  1804.                 goto erret;
  1805.  
  1806.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  1807.                 goto erret;
  1808.  
  1809.         if ((atp = AsnReadId(aip, amp, atp)) != ENTREZ_DOCGET_class)
  1810.                 goto erret;
  1811.         if (AsnReadVal(aip, atp, &av) <= 0)
  1812.                 goto erret;
  1813.         p->cls = av.intvalue;
  1814.  
  1815.         p->mark_missing = FALSE;
  1816.         if ((atp = AsnReadId(aip, amp, atp)) == ENTREZ_DOCGET_mark_missing)
  1817.         {
  1818.                 if (AsnReadVal(aip, atp, &av) <= 0)
  1819.                         goto erret;
  1820.                 p->mark_missing = av.boolvalue;
  1821.                 atp = AsnReadId(aip, amp, atp);
  1822.         }
  1823.  
  1824.         if (atp != ENTREZ_DOCGET_ids)
  1825.                 goto erret;
  1826.         p->ids = EntrezIdsAsnRead(aip, atp);
  1827.         if (p->ids == NULL)
  1828.                 goto erret;
  1829.  
  1830.         p->defer_count = 0;
  1831.         if ((atp = AsnReadId(aip, amp, atp)) == ENTREZ_DOCGET_defer_count)
  1832.         {
  1833.                 if (AsnReadVal(aip, atp, &av) < 0)
  1834.                         goto erret;
  1835.                 p->defer_count = av.intvalue;
  1836.                 atp = AsnReadId(aip, amp, atp);
  1837.         }
  1838.  
  1839.         if (orig == NULL)
  1840.         {
  1841.                 if (atp != ENTREZ_DOCGET)
  1842.                         goto erret;
  1843.         }
  1844.         else { /* check for "close struct" associated with "orig" */
  1845.                 if (atp != orig)
  1846.                         goto erret;
  1847.         }
  1848.  
  1849.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  1850.                 goto erret;
  1851.  
  1852. ret:
  1853.         AsnUnlinkType(orig);
  1854.         return p;
  1855.  
  1856. erret:
  1857.         p = EntrezDocGetFree(p);
  1858.         goto ret;
  1859. }
  1860.  
  1861. Boolean LIBCALL
  1862. EntrezDocGetAsnWrite (EntrezDocGetPtr p, AsnIoPtr aip, AsnTypePtr orig)
  1863. {
  1864.         DataVal av;
  1865.         Boolean retval = FALSE;
  1866.         AsnTypePtr atp;
  1867.  
  1868.         if (! NetEntAsnLoad() )
  1869.                 return FALSE;
  1870.  
  1871.         if (aip == NULL)
  1872.                 return FALSE;
  1873.  
  1874.         atp = AsnLinkType(orig, ENTREZ_DOCGET); /* link local tree */
  1875.  
  1876.         if (atp == NULL)
  1877.                 return FALSE;
  1878.  
  1879.         if (p == NULL)
  1880.         {
  1881.                 AsnNullValueMsg(aip, atp);
  1882.                 goto erret;
  1883.         }
  1884.  
  1885.         if (! AsnStartStruct(aip, atp))
  1886.                 goto erret;
  1887.  
  1888.         av.intvalue = p->cls;
  1889.         AsnWrite (aip, ENTREZ_DOCGET_class, &av);
  1890.         av.boolvalue = p->mark_missing;
  1891.         AsnWrite (aip, ENTREZ_DOCGET_mark_missing, &av);
  1892.     if (! EntrezIdsAsnWrite(p->ids, aip, ENTREZ_DOCGET_ids) )
  1893.                 goto erret;
  1894.         av.intvalue = p->defer_count;
  1895.         AsnWrite (aip, ENTREZ_DOCGET_defer_count, &av);
  1896.  
  1897.         if (! AsnEndStruct(aip, atp))
  1898.                 goto erret;
  1899.  
  1900.         retval = TRUE;
  1901.  
  1902. erret:
  1903.         AsnUnlinkType(orig); /* unlink local tree */
  1904.         return retval;
  1905. }
  1906.  
  1907.  
  1908. /************************** MedlineEntryList *********************************/
  1909.  
  1910. MedlineEntryListPtr LIBCALL
  1911. MedlineEntryListNew(void)
  1912. {
  1913.         MedlineEntryListPtr p;
  1914.  
  1915.         p = MemNew(sizeof(MedlineEntryList));
  1916.         if (p != NULL)
  1917.         {
  1918.                 p->num = 0;
  1919.                 p->data = NULL;
  1920.                 p->marked_missing = NULL;
  1921.         }
  1922.         return p;
  1923. }
  1924.  
  1925. MedlineEntryListPtr LIBCALL
  1926. MedlineEntryListFree(MedlineEntryListPtr p)
  1927. {
  1928.         Int4 i;
  1929.  
  1930.         if (p == NULL)
  1931.                 return NULL;
  1932.         if (p->data != NULL)
  1933.         {
  1934.                 for (i = 0; i < p->num; i++)
  1935.                         MedlineEntryFree(p->data[i]);
  1936.         }
  1937.         MemFree (p->data);
  1938.         EntrezIdsFree (p->marked_missing);
  1939.         return MemFree(p);
  1940. }
  1941.                 
  1942. MedlineEntryListPtr LIBCALL
  1943. MedlineEntryListAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  1944. {
  1945.         DataVal av;
  1946.         MedlineEntryListPtr p;
  1947.         AsnTypePtr atp;
  1948.         Int4 num;
  1949.  
  1950.         if (!NetEntAsnLoad())
  1951.                 return NULL;
  1952.         
  1953.         if (aip == NULL)
  1954.                 return NULL;
  1955.         
  1956.         if (orig == NULL)
  1957.                 atp = AsnReadId(aip, amp, ENTREZ_MEDLINE_ENTRY_LIST);
  1958.         else
  1959.                 atp = AsnLinkType(orig, ENTREZ_MEDLINE_ENTRY_LIST); /* link in local tree */
  1960.  
  1961.         if (atp == NULL)
  1962.                 return NULL;
  1963.  
  1964.         p = MedlineEntryListNew();
  1965.         if (p == NULL)
  1966.                 goto erret;
  1967.  
  1968.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  1969.                 goto erret;
  1970.  
  1971.         atp = AsnReadId(aip, amp, atp); /* find the num */
  1972.         if (atp == NULL)
  1973.                 goto erret;
  1974.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
  1975.                 goto erret;
  1976.         p->num = av.intvalue;
  1977.  
  1978.         atp = AsnReadId(aip, amp, atp); /* find the data start-struct */
  1979.         if (atp == NULL)
  1980.                 goto erret;
  1981.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the data start-struct */
  1982.                 goto erret;
  1983.  
  1984.         p->data = (MedlineEntryPtr PNTR) MemNew(sizeof(MedlineEntryPtr) * p->num);
  1985.         for (num = 0; num < p->num; num++)
  1986.                 p->data[num] = NULL;
  1987.         atp = AsnReadId(aip, amp, atp);
  1988.  
  1989.         for (num = 0; num < p->num && atp == MEDLINE_ENTRY_LIST_data_E; num++)
  1990.         {
  1991.                 if ((p->data[num] = MedlineEntryAsnRead(aip, atp)) == NULL)
  1992.                         goto erret;
  1993.                 atp = AsnReadId(aip, amp, atp);
  1994.         }
  1995.  
  1996.         /* check for count mis-match */
  1997.         if (num != p->num)
  1998.                 goto erret;
  1999.         
  2000.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2001.                 goto erret;
  2002.  
  2003.         atp = AsnReadId(aip, amp, atp);
  2004.  
  2005.         if (atp == ENTRY_LIST_marked_missing)
  2006.         {
  2007.                 p->marked_missing = EntrezIdsAsnRead(aip, atp);
  2008.                 atp = AsnReadId(aip, amp, atp);
  2009.         }
  2010.  
  2011.         if (orig == NULL)
  2012.         {
  2013.                 if (atp != ENTREZ_MEDLINE_ENTRY_LIST)
  2014.                         goto erret;
  2015.         }
  2016.         else { /* check for "close struct" associated with "orig" */
  2017.                 if (atp != orig)
  2018.                         goto erret;
  2019.         }
  2020.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2021.                 goto erret;
  2022.  
  2023. ret:
  2024.         AsnUnlinkType(orig);
  2025.         return p;
  2026.  
  2027. erret:
  2028.         p = MedlineEntryListFree(p);
  2029.         goto ret;
  2030. }
  2031.                 
  2032.  
  2033. Boolean LIBCALL
  2034. MedlineEntryListAsnWrite (MedlineEntryListPtr p, AsnIoPtr aip, AsnTypePtr orig)
  2035. {
  2036.         DataVal av;
  2037.         Int4 i;
  2038.         AsnTypePtr atp;
  2039.         Boolean retval = FALSE;
  2040.  
  2041.         if (! NetEntAsnLoad() )
  2042.                 return FALSE;
  2043.  
  2044.         if (aip == NULL)
  2045.                 return FALSE;
  2046.  
  2047.         atp = AsnLinkType(orig, ENTREZ_MEDLINE_ENTRY_LIST); /* link local tree */
  2048.  
  2049.         if (atp == NULL)
  2050.                 return FALSE;
  2051.  
  2052.         if (p == NULL)
  2053.         {
  2054.                 AsnNullValueMsg(aip, atp);
  2055.                 goto erret;
  2056.         }
  2057.  
  2058.         if (! AsnStartStruct(aip, atp))
  2059.                 goto erret;
  2060.         av.intvalue = p->num;
  2061.         AsnWrite (aip, ENTREZ_MEDLINE_ENTRY_LIST_num, &av);
  2062.  
  2063.         AsnStartStruct (aip, ENTREZ_MEDLINE_ENTRY_LIST_data);
  2064.         for (i = 0; i < p->num; i++)
  2065.         {
  2066.                 MedlineEntryAsnWrite(p->data[i], aip, MEDLINE_ENTRY_LIST_data_E);
  2067.         }
  2068.         AsnEndStruct (aip, ENTREZ_MEDLINE_ENTRY_LIST_data);
  2069.  
  2070.         if (p->marked_missing != NULL) /* optional */
  2071.         {
  2072.                 EntrezIdsAsnWrite(p->marked_missing, aip, ENTRY_LIST_marked_missing);
  2073.         }
  2074.  
  2075.         if (! AsnEndStruct(aip, atp))
  2076.                 goto erret;
  2077.  
  2078.         retval = TRUE;
  2079.  
  2080. erret:
  2081.         AsnUnlinkType(orig); /* unlink local tree */
  2082.         return retval;
  2083. }
  2084.  
  2085.  
  2086. /************************** MlSummaryList ****************************************/
  2087.  
  2088. MlSummaryListPtr LIBCALL
  2089. MlSummaryListNew(void)
  2090. {
  2091.         MlSummaryListPtr p;
  2092.  
  2093.         p = MemNew(sizeof(MlSummaryList));
  2094.         if (p != NULL)
  2095.         {
  2096.                 p->num = 0;
  2097.                 p->data = NULL;
  2098.         }
  2099.         return p;
  2100. }
  2101.  
  2102. MlSummaryListPtr LIBCALL
  2103. MlSummaryListFree(MlSummaryListPtr p)
  2104. {
  2105.         Int4 i;
  2106.  
  2107.         if (p == NULL)
  2108.                 return NULL;
  2109.         if (p->data != NULL)
  2110.         {
  2111.                 for (i = 0; i < p->num; i++)
  2112.                         MlSumFree(p->data[i]);
  2113.         }
  2114.         MemFree (p->data);
  2115.         return MemFree(p);
  2116. }
  2117.                 
  2118. MlSummaryListPtr LIBCALL
  2119. MlSummaryListAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  2120. {
  2121.         DataVal av;
  2122.         MlSummaryListPtr p;
  2123.         AsnTypePtr atp;
  2124.         Int4 num;
  2125.  
  2126.         if (!NetEntAsnLoad())
  2127.                 return NULL;
  2128.         
  2129.         if (aip == NULL)
  2130.                 return NULL;
  2131.         
  2132.         if (orig == NULL)
  2133.                 atp = AsnReadId(aip, amp, ML_SUMMARY_LIST);
  2134.         else
  2135.                 atp = AsnLinkType(orig, ML_SUMMARY_LIST); /* link in local tree */
  2136.  
  2137.         if (atp == NULL)
  2138.                 return NULL;
  2139.  
  2140.         p = MlSummaryListNew();
  2141.         if (p == NULL)
  2142.                 goto erret;
  2143.  
  2144.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  2145.                 goto erret;
  2146.  
  2147.         atp = AsnReadId(aip, amp, atp); /* find the num */
  2148.         if (atp == NULL)
  2149.                 goto erret;
  2150.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
  2151.                 goto erret;
  2152.         p->num = av.intvalue;
  2153.  
  2154.         atp = AsnReadId(aip, amp, atp); /* find the data start-struct */
  2155.         if (atp == NULL)
  2156.                 goto erret;
  2157.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the data start-struct */
  2158.                 goto erret;
  2159.  
  2160.         p->data = (DocSumPtr PNTR) MemNew(sizeof(DocSumPtr) * p->num);
  2161.         for (num = 0; num < p->num; num++)
  2162.                 p->data[num] = NULL;
  2163.         atp = AsnReadId(aip, amp, atp);
  2164.  
  2165.         for (num = 0; num < p->num && atp == ML_SUMMARY_LIST_data_E; num++)
  2166.         {
  2167.                 if ((p->data[num] = MlSumAsnRead(aip, atp)) == NULL)
  2168.                         goto erret;
  2169.                 atp = AsnReadId(aip, amp, atp);
  2170.         }
  2171.  
  2172.         /* check for count mis-match */
  2173.         if (num != p->num || atp != ML_SUMMARY_LIST_data)
  2174.                 goto erret;
  2175.  
  2176.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2177.                 goto erret;
  2178.  
  2179.         atp = AsnReadId(aip, amp, atp);
  2180.         if (orig == NULL)
  2181.         {
  2182.                 if (atp != ML_SUMMARY_LIST)
  2183.                         goto erret;
  2184.         }
  2185.         else { /* check for "close struct" associated with "orig" */
  2186.                 if (atp != orig)
  2187.                         goto erret;
  2188.         }
  2189.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2190.                 goto erret;
  2191.  
  2192. ret:
  2193.         AsnUnlinkType(orig);
  2194.         return p;
  2195.  
  2196. erret:
  2197.         p = MlSummaryListFree(p);
  2198.         goto ret;
  2199. }
  2200.                 
  2201.  
  2202. Boolean LIBCALL
  2203. MlSummaryListAsnWrite (MlSummaryListPtr p, AsnIoPtr aip, AsnTypePtr orig)
  2204. {
  2205.         DataVal av;
  2206.         Int4 i;
  2207.         AsnTypePtr atp;
  2208.         Boolean retval = FALSE;
  2209.  
  2210.         if (! NetEntAsnLoad() )
  2211.                 return FALSE;
  2212.  
  2213.         if (aip == NULL)
  2214.                 return FALSE;
  2215.  
  2216.         atp = AsnLinkType(orig, ML_SUMMARY_LIST); /* link local tree */
  2217.  
  2218.         if (atp == NULL)
  2219.                 return FALSE;
  2220.  
  2221.         if (p == NULL)
  2222.         {
  2223.                 AsnNullValueMsg(aip, atp);
  2224.                 goto erret;
  2225.         }
  2226.  
  2227.         if (! AsnStartStruct(aip, atp))
  2228.                 goto erret;
  2229.         av.intvalue = p->num;
  2230.         AsnWrite (aip, ML_SUMMARY_LIST_num, &av);
  2231.  
  2232.         AsnStartStruct (aip, ML_SUMMARY_LIST_data);
  2233.         for (i = 0; i < p->num; i++)
  2234.         {
  2235.                 MlSumAsnWrite(p->data[i], aip, ML_SUMMARY_LIST_data_E);
  2236.         }
  2237.         AsnEndStruct (aip, ML_SUMMARY_LIST_data);
  2238.  
  2239.         if (! AsnEndStruct(aip, atp))
  2240.                 goto erret;
  2241.  
  2242.         retval = TRUE;
  2243.  
  2244. erret:
  2245.         AsnUnlinkType(orig); /* unlink local tree */
  2246.         return retval;
  2247. }
  2248.  
  2249. /************************** EntrezSeqGet **************************************/
  2250.  
  2251. EntrezSeqGetPtr LIBCALL
  2252. EntrezSeqGetNew(void)
  2253. {
  2254.         EntrezSeqGetPtr p;
  2255.  
  2256.         p = MemNew(sizeof(EntrezSeqGet));
  2257.         if (p != NULL)
  2258.         {
  2259.                 p->ids = NULL;
  2260.         }
  2261.         return p;
  2262. }
  2263.  
  2264. EntrezSeqGetPtr LIBCALL
  2265. EntrezSeqGetFree(EntrezSeqGetPtr p)
  2266. {
  2267.         if (p == NULL)
  2268.                 return NULL;
  2269.         EntrezIdsFree (p->ids);
  2270.         return MemFree(p);
  2271. }
  2272.                 
  2273. EntrezSeqGetPtr LIBCALL
  2274. EntrezSeqGetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  2275. {
  2276.         DataVal av;
  2277.         EntrezSeqGetPtr p;
  2278.         AsnTypePtr atp;
  2279.  
  2280.         if (!NetEntAsnLoad())
  2281.                 return NULL;
  2282.         
  2283.         if (aip == NULL)
  2284.                 return NULL;
  2285.         
  2286.         if (orig == NULL)
  2287.                 atp = AsnReadId(aip, amp, ENTREZ_SEQGET);
  2288.         else
  2289.                 atp = AsnLinkType(orig, ENTREZ_SEQGET); /* link in local tree */
  2290.  
  2291.         if (atp == NULL)
  2292.                 return NULL;
  2293.  
  2294.         p = EntrezSeqGetNew();
  2295.         if (p == NULL)
  2296.                 goto erret;
  2297.  
  2298.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  2299.                 goto erret;
  2300.  
  2301.         atp = AsnReadId(aip, amp, atp);
  2302.         if (atp == NULL)
  2303.                 goto erret;
  2304.         if (AsnReadVal(aip, atp, &av) <= 0)
  2305.                 goto erret;
  2306.         p->retype = av.intvalue;
  2307.  
  2308.         p->mark_missing = FALSE;
  2309.         atp = AsnReadId(aip, amp, atp);
  2310.         if (atp == ENTREZ_SEQGET_mark_missing) {
  2311.                 if (AsnReadVal(aip, atp, &av) <= 0)
  2312.                         goto erret;
  2313.                 p->mark_missing = av.boolvalue;
  2314.                 atp = AsnReadId(aip, amp, atp);
  2315.         }
  2316.  
  2317.         if (atp == NULL)
  2318.                 goto erret;
  2319.         p->ids = EntrezIdsAsnRead(aip, atp);
  2320.  
  2321.         atp = AsnReadId(aip, amp, atp);
  2322.         if (orig == NULL)
  2323.         {
  2324.                 if (atp != ENTREZ_SEQGET)
  2325.                         goto erret;
  2326.         }
  2327.         else { /* check for "close struct" associated with "orig" */
  2328.                 if (atp != orig)
  2329.                         goto erret;
  2330.         }
  2331.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2332.                 goto erret;
  2333.  
  2334. ret:
  2335.         AsnUnlinkType(orig);
  2336.         return p;
  2337.  
  2338. erret:
  2339.         p = EntrezSeqGetFree(p);
  2340.         goto ret;
  2341. }
  2342.                 
  2343.  
  2344. Boolean LIBCALL
  2345. EntrezSeqGetAsnWrite (EntrezSeqGetPtr p, AsnIoPtr aip, AsnTypePtr orig)
  2346. {
  2347.         DataVal av;
  2348.         AsnTypePtr atp;
  2349.         Boolean retval = FALSE;
  2350.  
  2351.         if (! NetEntAsnLoad() )
  2352.                 return FALSE;
  2353.  
  2354.         if (aip == NULL)
  2355.                 return FALSE;
  2356.  
  2357.         atp = AsnLinkType(orig, ENTREZ_SEQGET); /* link local tree */
  2358.  
  2359.         if (atp == NULL)
  2360.                 return FALSE;
  2361.  
  2362.         if (p == NULL)
  2363.         {
  2364.                 AsnNullValueMsg(aip, atp);
  2365.                 goto erret;
  2366.         }
  2367.  
  2368.         if (! AsnStartStruct(aip, atp))
  2369.                 goto erret;
  2370.         av.intvalue = p->retype;
  2371.         AsnWrite (aip, ENTREZ_SEQGET_retype, &av);
  2372.         av.boolvalue = p->mark_missing;
  2373.         AsnWrite (aip, ENTREZ_SEQGET_mark_missing, &av);
  2374.         EntrezIdsAsnWrite(p->ids, aip, ENTREZ_SEQGET_ids);
  2375.  
  2376.         if (! AsnEndStruct(aip, atp))
  2377.                 goto erret;
  2378.  
  2379.         retval = TRUE;
  2380.  
  2381. erret:
  2382.         AsnUnlinkType(orig); /* unlink local tree */
  2383.         return retval;
  2384. }
  2385.  
  2386.  
  2387. /************************** SeqSummaryList ****************************************/
  2388.  
  2389. SeqSummaryListPtr LIBCALL
  2390. SeqSummaryListNew(void)
  2391. {
  2392.         SeqSummaryListPtr p;
  2393.  
  2394.         p = MemNew(sizeof(SeqSummaryList));
  2395.         if (p != NULL)
  2396.         {
  2397.                 p->num = 0;
  2398.                 p->data = NULL;
  2399.         }
  2400.         return p;
  2401. }
  2402.  
  2403. SeqSummaryListPtr LIBCALL
  2404. SeqSummaryListFree(SeqSummaryListPtr p)
  2405. {
  2406.         Int4 i;
  2407.  
  2408.         if (p == NULL)
  2409.                 return NULL;
  2410.         if (p->data != NULL)
  2411.         {
  2412.                 for (i = 0; i < p->num; i++)
  2413.                         SeqSumFree(p->data[i]);
  2414.         }
  2415.         MemFree (p->data);
  2416.         return MemFree(p);
  2417. }
  2418.                 
  2419. SeqSummaryListPtr LIBCALL
  2420. SeqSummaryListAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  2421. {
  2422.         DataVal av;
  2423.         SeqSummaryListPtr p;
  2424.         AsnTypePtr atp;
  2425.         Int4 num;
  2426.  
  2427.         if (!NetEntAsnLoad())
  2428.                 return NULL;
  2429.         
  2430.         if (aip == NULL)
  2431.                 return NULL;
  2432.         
  2433.         if (orig == NULL)
  2434.                 atp = AsnReadId(aip, amp, SEQ_SUMMARY_LIST);
  2435.         else
  2436.                 atp = AsnLinkType(orig, SEQ_SUMMARY_LIST); /* link in local tree */
  2437.  
  2438.         if (atp == NULL)
  2439.                 return NULL;
  2440.  
  2441.         p = SeqSummaryListNew();
  2442.         if (p == NULL)
  2443.                 goto erret;
  2444.  
  2445.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  2446.                 goto erret;
  2447.  
  2448.         atp = AsnReadId(aip, amp, atp); /* find the num */
  2449.         if (atp == NULL)
  2450.                 goto erret;
  2451.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
  2452.                 goto erret;
  2453.         p->num = av.intvalue;
  2454.  
  2455.         atp = AsnReadId(aip, amp, atp); /* find the data start-struct */
  2456.         if (atp == NULL)
  2457.                 goto erret;
  2458.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the data start-struct */
  2459.                 goto erret;
  2460.  
  2461.         p->data = (DocSumPtr PNTR) MemNew(sizeof(DocSumPtr) * (size_t) p->num);
  2462.         for (num = 0; num < p->num; num++)
  2463.                 p->data[num] = NULL;
  2464.         atp = AsnReadId(aip, amp, atp);
  2465.  
  2466.         for (num = 0; num < p->num && atp == SEQ_SUMMARY_LIST_data_E; num++)
  2467.         {
  2468.                 if ((p->data[num] = SeqSumAsnRead(aip, atp)) == NULL)
  2469.                         goto erret;
  2470.                 atp = AsnReadId(aip, amp, atp);
  2471.         }
  2472.  
  2473.         /* check for count mis-match */
  2474.         if (num != p->num || atp != SEQ_SUMMARY_LIST_data)
  2475.                 goto erret;
  2476.  
  2477.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2478.                 goto erret;
  2479.  
  2480.         atp = AsnReadId(aip, amp, atp);
  2481.         if (orig == NULL)
  2482.         {
  2483.                 if (atp != SEQ_SUMMARY_LIST)
  2484.                         goto erret;
  2485.         }
  2486.         else { /* check for "close struct" associated with "orig" */
  2487.                 if (atp != orig)
  2488.                         goto erret;
  2489.         }
  2490.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2491.                 goto erret;
  2492.  
  2493. ret:
  2494.         AsnUnlinkType(orig);
  2495.         return p;
  2496.  
  2497. erret:
  2498.         p = SeqSummaryListFree(p);
  2499.         goto ret;
  2500. }
  2501.                 
  2502.  
  2503. Boolean LIBCALL
  2504. SeqSummaryListAsnWrite (SeqSummaryListPtr p, AsnIoPtr aip, AsnTypePtr orig)
  2505. {
  2506.         DataVal av;
  2507.         Int4 i;
  2508.         AsnTypePtr atp;
  2509.         Boolean retval = FALSE;
  2510.  
  2511.         if (! NetEntAsnLoad() )
  2512.                 return FALSE;
  2513.  
  2514.         if (aip == NULL)
  2515.                 return FALSE;
  2516.  
  2517.         atp = AsnLinkType(orig, SEQ_SUMMARY_LIST); /* link local tree */
  2518.  
  2519.         if (atp == NULL)
  2520.                 return FALSE;
  2521.  
  2522.         if (p == NULL)
  2523.         {
  2524.                 AsnNullValueMsg(aip, atp);
  2525.                 goto erret;
  2526.         }
  2527.  
  2528.         if (! AsnStartStruct(aip, atp))
  2529.                 goto erret;
  2530.         av.intvalue = p->num;
  2531.         AsnWrite (aip, SEQ_SUMMARY_LIST_num, &av);
  2532.  
  2533.         AsnStartStruct (aip, SEQ_SUMMARY_LIST_data);
  2534.         for (i = 0; i < p->num; i++)
  2535.         {
  2536.                 SeqSumAsnWrite(p->data[i], aip, SEQ_SUMMARY_LIST_data_E);
  2537.         }
  2538.         AsnEndStruct (aip, SEQ_SUMMARY_LIST_data);
  2539.  
  2540.         if (! AsnEndStruct(aip, atp))
  2541.                 goto erret;
  2542.  
  2543.         retval = TRUE;
  2544.  
  2545. erret:
  2546.         AsnUnlinkType(orig); /* unlink local tree */
  2547.         return retval;
  2548. }
  2549.  
  2550. /************************** SeqEntryList **************************************/
  2551.  
  2552. SeqEntryListPtr LIBCALL
  2553. SeqEntryListNew(void)
  2554. {
  2555.         SeqEntryListPtr p;
  2556.  
  2557.         p = MemNew(sizeof(*p));
  2558.         if (p != NULL)
  2559.         {
  2560.                 p->num = 0;
  2561.                 p->data = NULL;
  2562.                 p->marked_missing = NULL;
  2563.         }
  2564.         return p;
  2565. }
  2566.  
  2567. SeqEntryListPtr LIBCALL
  2568. SeqEntryListFree(SeqEntryListPtr p)
  2569. {
  2570.         Int4 i;
  2571.  
  2572.         if (p == NULL)
  2573.                 return NULL;
  2574.         if (p->data != NULL)
  2575.         {
  2576.                 for (i = 0; i < p->num; i++)
  2577.                         SeqEntryFree(p->data[i]);
  2578.         }
  2579.         MemFree (p->data);
  2580.         EntrezIdsFree (p->marked_missing);
  2581.         return MemFree(p);
  2582. }
  2583.                 
  2584. SeqEntryListPtr LIBCALL
  2585. SeqEntryListAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  2586. {
  2587.         DataVal av;
  2588.         SeqEntryListPtr p;
  2589.         AsnTypePtr atp;
  2590.         Int4 num;
  2591.  
  2592.         if (!NetEntAsnLoad())
  2593.                 return NULL;
  2594.         
  2595.         if (aip == NULL)
  2596.                 return NULL;
  2597.         
  2598.         if (orig == NULL)
  2599.                 atp = AsnReadId(aip, amp, ENTREZ_SEQ_ENTRY_LIST);
  2600.         else
  2601.                 atp = AsnLinkType(orig, ENTREZ_SEQ_ENTRY_LIST); /* link in local tree */
  2602.  
  2603.         if (atp == NULL)
  2604.                 return NULL;
  2605.  
  2606.         p = SeqEntryListNew();
  2607.         if (p == NULL)
  2608.                 goto erret;
  2609.  
  2610.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  2611.                 goto erret;
  2612.  
  2613.         atp = AsnReadId(aip, amp, atp); /* find the num */
  2614.         if (atp == NULL)
  2615.                 goto erret;
  2616.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
  2617.                 goto erret;
  2618.         p->num = av.intvalue;
  2619.  
  2620.         atp = AsnReadId(aip, amp, atp); /* find the data start-struct */
  2621.         if (atp == NULL)
  2622.                 goto erret;
  2623.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the data start-struct */
  2624.                 goto erret;
  2625.  
  2626.         p->data = (SeqEntryPtr PNTR) MemNew(sizeof(SeqEntryPtr) * p->num);
  2627.         for (num = 0; num < p->num; num++)
  2628.                 p->data[num] = NULL;
  2629.         atp = AsnReadId(aip, amp, atp);
  2630.  
  2631.         for (num = 0; num < p->num && atp == ENTREZ_SEQ_ENTRY_LIST_data_E; num++)
  2632.         {
  2633.                 if ((p->data[num] = SeqEntryAsnRead(aip, atp)) == NULL)
  2634.                         goto erret;
  2635.                 atp = AsnReadId(aip, amp, atp);
  2636.         }
  2637.  
  2638.         /* check for count mis-match */
  2639.         if (num != p->num)
  2640.                 goto erret;
  2641.         
  2642.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2643.                 goto erret;
  2644.  
  2645.         atp = AsnReadId(aip, amp, atp);
  2646.         if (atp == SEQ_ENTRY_LIST_marked_missing)
  2647.         {
  2648.                 p->marked_missing = EntrezIdsAsnRead(aip, atp);
  2649.                 atp = AsnReadId(aip, amp, atp);
  2650.         }
  2651.  
  2652.         if (orig == NULL)
  2653.         {
  2654.                 if (atp != ENTREZ_SEQ_ENTRY_LIST)
  2655.                         goto erret;
  2656.         }
  2657.         else { /* check for "close struct" associated with "orig" */
  2658.                 if (atp != orig)
  2659.                         goto erret;
  2660.         }
  2661.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2662.                 goto erret;
  2663.  
  2664. ret:
  2665.         AsnUnlinkType(orig);
  2666.         return p;
  2667.  
  2668. erret:
  2669.         p = SeqEntryListFree(p);
  2670.         goto ret;
  2671. }
  2672.                 
  2673.  
  2674. Boolean LIBCALL
  2675. SeqEntryListAsnWrite (SeqEntryListPtr p, AsnIoPtr aip, AsnTypePtr orig)
  2676. {
  2677.         DataVal av;
  2678.         Int4 i;
  2679.         AsnTypePtr atp;
  2680.         Boolean retval = FALSE;
  2681.  
  2682.         if (! NetEntAsnLoad() )
  2683.                 return FALSE;
  2684.  
  2685.         if (aip == NULL)
  2686.                 return FALSE;
  2687.  
  2688.         atp = AsnLinkType(orig, ENTREZ_SEQ_ENTRY_LIST); /* link local tree */
  2689.  
  2690.         if (atp == NULL)
  2691.                 return FALSE;
  2692.  
  2693.         if (p == NULL)
  2694.         {
  2695.                 AsnNullValueMsg(aip, atp);
  2696.                 goto erret;
  2697.         }
  2698.  
  2699.         if (! AsnStartStruct(aip, atp))
  2700.                 goto erret;
  2701.         av.intvalue = p->num;
  2702.         AsnWrite (aip, ENTREZ_SEQ_ENTRY_LIST_num, &av);
  2703.  
  2704.         AsnStartStruct (aip, ENTREZ_SEQ_ENTRY_LIST_data);
  2705.         for (i = 0; i < p->num; i++)
  2706.         {
  2707.                 SeqEntryAsnWrite(p->data[i], aip, ENTREZ_SEQ_ENTRY_LIST_data_E);
  2708.         }
  2709.         AsnEndStruct (aip, ENTREZ_SEQ_ENTRY_LIST_data);
  2710.  
  2711.         if (p->marked_missing != NULL) /* optional */
  2712.         {
  2713.                 EntrezIdsAsnWrite(p->marked_missing, aip, SEQ_ENTRY_LIST_marked_missing);
  2714.         }
  2715.  
  2716.         if (! AsnEndStruct(aip, atp))
  2717.                 goto erret;
  2718.  
  2719.         retval = TRUE;
  2720.  
  2721. erret:
  2722.         AsnUnlinkType(orig); /* unlink local tree */
  2723.         return retval;
  2724. }
  2725.  
  2726. #ifdef Biostruc_supported
  2727. /************************** BiostrucList *********************************/
  2728.  
  2729. BiostrucListPtr LIBCALL
  2730. BiostrucListNew(void)
  2731. {
  2732.         BiostrucListPtr p;
  2733.  
  2734.         p = MemNew(sizeof(BiostrucList));
  2735.         if (p != NULL)
  2736.         {
  2737.                 p->num = 0;
  2738.                 p->data = NULL;
  2739.                 p->marked_missing = NULL;
  2740.         }
  2741.         return p;
  2742. }
  2743.  
  2744. BiostrucListPtr LIBCALL
  2745. BiostrucListFree(BiostrucListPtr p)
  2746. {
  2747.         Int4 i;
  2748.  
  2749.         if (p == NULL)
  2750.                 return NULL;
  2751.         if (p->data != NULL)
  2752.         {
  2753.                 for (i = 0; i < p->num; i++)
  2754.                         BiostrucFree(p->data[i]);
  2755.         }
  2756.         MemFree (p->data);
  2757.         EntrezIdsFree (p->marked_missing);
  2758.         return MemFree(p);
  2759. }
  2760.                 
  2761. BiostrucListPtr LIBCALL
  2762. BiostrucListAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  2763. {
  2764.         DataVal av;
  2765.         BiostrucListPtr p;
  2766.         AsnTypePtr atp;
  2767.         Int4 num;
  2768.  
  2769.         if (!NetEntAsnLoad())
  2770.                 return NULL;
  2771.         
  2772.         if (aip == NULL)
  2773.                 return NULL;
  2774.         
  2775.         if (orig == NULL)
  2776.                 atp = AsnReadId(aip, amp, ENTREZ_BIOSTRUC_LIST);
  2777.         else
  2778.                 atp = AsnLinkType(orig, ENTREZ_BIOSTRUC_LIST); /* link in local tree */
  2779.  
  2780.         if (atp == NULL)
  2781.                 return NULL;
  2782.  
  2783.         p = BiostrucListNew();
  2784.         if (p == NULL)
  2785.                 goto erret;
  2786.  
  2787.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  2788.                 goto erret;
  2789.  
  2790.         atp = AsnReadId(aip, amp, atp); /* find the num */
  2791.         if (atp == NULL)
  2792.                 goto erret;
  2793.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
  2794.                 goto erret;
  2795.         p->num = av.intvalue;
  2796.  
  2797.         atp = AsnReadId(aip, amp, atp); /* find the data start-struct */
  2798.         if (atp == NULL)
  2799.                 goto erret;
  2800.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the data start-struct */
  2801.                 goto erret;
  2802.  
  2803.         p->data = (BiostrucPtr PNTR) MemNew(sizeof(BiostrucPtr) * p->num);
  2804.         for (num = 0; num < p->num; num++)
  2805.                 p->data[num] = NULL;
  2806.         atp = AsnReadId(aip, amp, atp);
  2807.  
  2808.         for (num = 0; num < p->num && atp == ENTREZ_BIOSTRUC_LIST_data_E; num++)
  2809.         {
  2810.                 if ((p->data[num] = BiostrucAsnRead(aip, atp)) == NULL)
  2811.                         goto erret;
  2812.                 atp = AsnReadId(aip, amp, atp);
  2813.         }
  2814.  
  2815.         /* check for count mis-match */
  2816.         if (num != p->num)
  2817.                 goto erret;
  2818.         
  2819.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2820.                 goto erret;
  2821.  
  2822.         atp = AsnReadId(aip, amp, atp);
  2823.  
  2824.         if (atp == BIOSTRUC_LIST_marked_missing)
  2825.         {
  2826.                 p->marked_missing = EntrezIdsAsnRead(aip, atp);
  2827.                 atp = AsnReadId(aip, amp, atp);
  2828.         }
  2829.  
  2830.         if (orig == NULL)
  2831.         {
  2832.                 if (atp != ENTREZ_BIOSTRUC_LIST)
  2833.                         goto erret;
  2834.         }
  2835.         else { /* check for "close struct" associated with "orig" */
  2836.                 if (atp != orig)
  2837.                         goto erret;
  2838.         }
  2839.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  2840.                 goto erret;
  2841.  
  2842. ret:
  2843.         AsnUnlinkType(orig);
  2844.         return p;
  2845.  
  2846. erret:
  2847.         p = BiostrucListFree(p);
  2848.         goto ret;
  2849. }
  2850.                 
  2851.  
  2852. Boolean LIBCALL
  2853. BiostrucListAsnWrite (BiostrucListPtr p, AsnIoPtr aip, AsnTypePtr orig)
  2854. {
  2855.         DataVal av;
  2856.         Int4 i;
  2857.         AsnTypePtr atp;
  2858.         Boolean retval = FALSE;
  2859.  
  2860.         if (! NetEntAsnLoad() )
  2861.                 return FALSE;
  2862.  
  2863.         if (aip == NULL)
  2864.                 return FALSE;
  2865.  
  2866.         atp = AsnLinkType(orig, ENTREZ_BIOSTRUC_LIST); /* link local tree */
  2867.  
  2868.         if (atp == NULL)
  2869.                 return FALSE;
  2870.  
  2871.         if (p == NULL)
  2872.         {
  2873.                 AsnNullValueMsg(aip, atp);
  2874.                 goto erret;
  2875.         }
  2876.  
  2877.         if (! AsnStartStruct(aip, atp))
  2878.                 goto erret;
  2879.         av.intvalue = p->num;
  2880.         AsnWrite (aip, ENTREZ_BIOSTRUC_LIST_num, &av);
  2881.  
  2882.         AsnStartStruct (aip, ENTREZ_BIOSTRUC_LIST_data);
  2883.         for (i = 0; i < p->num; i++)
  2884.         {
  2885.                 BiostrucAsnWrite(p->data[i], aip, ENTREZ_BIOSTRUC_LIST_data_E);
  2886.         }
  2887.         AsnEndStruct (aip, ENTREZ_BIOSTRUC_LIST_data);
  2888.  
  2889.         if (p->marked_missing != NULL) /* optional */
  2890.         {
  2891.                 EntrezIdsAsnWrite(p->marked_missing, aip, BIOSTRUC_LIST_marked_missing);
  2892.         }
  2893.  
  2894.         if (! AsnEndStruct(aip, atp))
  2895.                 goto erret;
  2896.  
  2897.         retval = TRUE;
  2898.  
  2899. erret:
  2900.         AsnUnlinkType(orig); /* unlink local tree */
  2901.         return retval;
  2902. }
  2903.  
  2904.  
  2905. #endif /* Biostruc_supported */
  2906.  
  2907. /**************************************************
  2908. *
  2909. *    EntrezNeighborTextAsnRead()
  2910. *
  2911. **************************************************/
  2912.  
  2913. EntrezNeighborTextPtr LIBCALL
  2914. EntrezNeighborTextAsnRead(AsnIoPtr aip, AsnTypePtr orig)
  2915. {
  2916.    DataVal av;
  2917.    AsnTypePtr atp;
  2918.    AsnReadFunc func;
  2919.    EntrezNeighborTextPtr ptr;
  2920.  
  2921.    if (! NetEntAsnLoad())
  2922.       return NULL;
  2923.  
  2924.    if (aip == NULL) {
  2925.       return NULL;
  2926.    }
  2927.  
  2928.    if (orig == NULL) {         /* EntrezNeighborText ::= (self contained) */
  2929.       atp = AsnReadId(aip, amp, ENTREZ_NEIGHBOR_TEXT);
  2930.    } else {
  2931.       atp = AsnLinkType(orig, ENTREZ_NEIGHBOR_TEXT);
  2932.    }
  2933.    /* link in local tree */
  2934.    if (atp == NULL) {
  2935.       return NULL;
  2936.    }
  2937.  
  2938.    ptr = EntrezNeighborTextNew();
  2939.    if (ptr == NULL) {
  2940.       goto erret;
  2941.    }
  2942.    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
  2943.       goto erret;
  2944.    }
  2945.  
  2946.    func = NULL;
  2947.  
  2948.    atp = AsnReadId(aip,amp, atp);
  2949.    if (atp == ENTREZ_NEIGHBOR_TEXT_fld) {
  2950.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  2951.          goto erret;
  2952.       }
  2953.       ptr -> fld =av.intvalue;
  2954.       atp = AsnReadId(aip,amp, atp);
  2955.    }
  2956.    if (atp == TEXT_percent_terms_to_use) {
  2957.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  2958.          goto erret;
  2959.       }
  2960.       ptr -> percent_terms_to_use =av.intvalue;
  2961.       atp = AsnReadId(aip,amp, atp);
  2962.    }
  2963.    if (atp == NEIGHBOR_TEXT_max_neighbors) {
  2964.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  2965.          goto erret;
  2966.       }
  2967.       ptr -> max_neighbors =av.intvalue;
  2968.       atp = AsnReadId(aip,amp, atp);
  2969.    }
  2970.    if (atp == ENTREZ_NEIGHBOR_TEXT_min_score) {
  2971.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  2972.          goto erret;
  2973.       }
  2974.       ptr -> min_score =av.intvalue;
  2975.       atp = AsnReadId(aip,amp, atp);
  2976.    }
  2977.    if (atp == NEIGHBOR_TEXT_normal_text) {
  2978.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  2979.          goto erret;
  2980.       }
  2981.       ptr -> normalText =av.ptrvalue;
  2982.       atp = AsnReadId(aip,amp, atp);
  2983.    }
  2984.    if (atp == NEIGHBOR_TEXT_special_text) {
  2985.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  2986.          goto erret;
  2987.       }
  2988.       ptr -> specialText =av.ptrvalue;
  2989.       atp = AsnReadId(aip,amp, atp);
  2990.    }
  2991.  
  2992.    if (AsnReadVal(aip, atp, &av) <= 0) {
  2993.       goto erret;
  2994.    }
  2995.    /* end struct */
  2996.  
  2997. ret:
  2998.    AsnUnlinkType(orig);       /* unlink local tree */
  2999.    return ptr;
  3000.  
  3001. erret:
  3002.    ptr = EntrezNeighborTextFree(ptr);
  3003.    goto ret;
  3004. }
  3005.  
  3006.  
  3007.  
  3008. /**************************************************
  3009. *
  3010. *    EntrezNeighborTextAsnWrite()
  3011. *
  3012. **************************************************/
  3013. Boolean LIBCALL 
  3014. EntrezNeighborTextAsnWrite(EntrezNeighborTextPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
  3015. {
  3016.    DataVal av;
  3017.    AsnTypePtr atp;
  3018.    Boolean retval = FALSE;
  3019.  
  3020.    if (! NetEntAsnLoad() )
  3021.       return FALSE;
  3022.  
  3023.    if (aip == NULL) {
  3024.       return FALSE;
  3025.    }
  3026.  
  3027.    atp = AsnLinkType(orig, ENTREZ_NEIGHBOR_TEXT);   /* link local tree */
  3028.    if (atp == NULL) {
  3029.       return FALSE;
  3030.    }
  3031.  
  3032.    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
  3033.  
  3034.    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
  3035.       goto erret;
  3036.    }
  3037.  
  3038.    av.intvalue = ptr -> fld;
  3039.    retval = AsnWrite(aip, ENTREZ_NEIGHBOR_TEXT_fld,  &av);
  3040.    av.intvalue = ptr -> percent_terms_to_use;
  3041.    retval = AsnWrite(aip, TEXT_percent_terms_to_use,  &av);
  3042.    av.intvalue = ptr -> max_neighbors;
  3043.    retval = AsnWrite(aip, NEIGHBOR_TEXT_max_neighbors,  &av);
  3044.    av.intvalue = ptr -> min_score;
  3045.    retval = AsnWrite(aip, ENTREZ_NEIGHBOR_TEXT_min_score,  &av);
  3046.  
  3047.    if (ptr -> normalText != NULL) {
  3048.       av.ptrvalue = ptr -> normalText;
  3049.       retval = AsnWrite(aip, NEIGHBOR_TEXT_normal_text,  &av);
  3050.    }
  3051.  
  3052.    if (ptr -> specialText != NULL) {
  3053.       av.ptrvalue = ptr -> specialText;
  3054.       retval = AsnWrite(aip, NEIGHBOR_TEXT_special_text,  &av);
  3055.    }
  3056.  
  3057.    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
  3058.       goto erret;
  3059.    }
  3060.    retval = TRUE;
  3061.  
  3062. erret:
  3063.    AsnUnlinkType(orig);       /* unlink local tree */
  3064.    return retval;
  3065. }
  3066.  
  3067.  
  3068. /**************************************************
  3069. *
  3070. *    ChildLinkNew()
  3071. *
  3072. ***************************************************/
  3073.  
  3074. static ChildLinkPtr LIBCALL ChildLinkNew(void)
  3075. {
  3076.    ChildLinkPtr ptr = MemNew((size_t) sizeof(ChildLink));
  3077.    return ptr;
  3078.  
  3079. }
  3080.  
  3081.  
  3082. /**************************************************
  3083. *
  3084. *    ChildLinkFree()
  3085. *
  3086. **************************************************/
  3087.  
  3088. static ChildLinkPtr LIBCALL ChildLinkFree(ChildLinkPtr ptr)
  3089. {
  3090.  
  3091.    if(ptr == NULL) 
  3092.      {
  3093.        return NULL;
  3094.      }
  3095.    MemFree(ptr -> name);
  3096.    return MemFree(ptr);
  3097. }
  3098.  
  3099. /******************************************
  3100. *
  3101. *      ChildLinkedListFree()
  3102. *
  3103. *******************************************/
  3104.  
  3105. static void LIBCALL ChildLinkedListFree(ChildLinkPtr ptr)
  3106. {
  3107.   ChildLinkPtr next;
  3108.   while(ptr != NULL)
  3109.     {
  3110.       next = ptr -> next;
  3111.       ChildLinkFree(ptr);
  3112.       ptr = next;
  3113.     }
  3114. }
  3115.  
  3116.       
  3117.  
  3118. /**************************************************
  3119. *
  3120. *    ChildLinkAsnRead()
  3121. *
  3122. **************************************************/
  3123.  
  3124. static ChildLinkPtr LIBCALL ChildLinkAsnRead(AsnIoPtr aip, AsnTypePtr orig)
  3125. {
  3126.    DataVal av;
  3127.    AsnTypePtr atp;
  3128.    Boolean isError;
  3129.    AsnReadFunc func;
  3130.    ChildLinkPtr ChildPtr;
  3131.  
  3132.    if (! loaded)
  3133.    {
  3134.       if (! NetEntAsnLoad()) {
  3135.          return NULL;
  3136.       }
  3137.    }
  3138.  
  3139.    if (aip == NULL) {
  3140.       return NULL;
  3141.    }
  3142.  
  3143.    if (orig == NULL) {     
  3144.       atp = AsnReadId(aip, amp, ENTREZ_TREE_CHILD);
  3145.    } else {
  3146.       atp = AsnLinkType(orig, ENTREZ_TREE_CHILD);
  3147.    }
  3148.    /* link in local tree */
  3149.    if (atp == NULL) {
  3150.       return NULL;
  3151.    }
  3152.  
  3153.    ChildPtr = ChildLinkNew();
  3154.    if (ChildPtr == NULL) {
  3155.       goto erret;
  3156.    }
  3157.    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
  3158.       goto erret;
  3159.    }
  3160.  
  3161.    func = NULL;
  3162.  
  3163.    atp = AsnReadId(aip,amp, atp);
  3164.    if (atp == ENTREZ_TREE_CHILD_name) {
  3165.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3166.          goto erret;
  3167.       }
  3168.       ChildPtr -> name = av.ptrvalue;
  3169.       atp = AsnReadId(aip,amp, atp);
  3170.    }
  3171.    if (atp == ENTREZ_TREE_CHILD_is_leaf_node) {
  3172.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3173.          goto erret;
  3174.       }
  3175.       ChildPtr -> isLeafNode = av.boolvalue;
  3176.       atp = AsnReadId(aip,amp, atp);
  3177.    }
  3178.    if (atp == ENTREZ_TREE_CHILD_special) {
  3179.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3180.          goto erret;
  3181.       }
  3182.       ChildPtr -> special = av.intvalue;
  3183.       atp = AsnReadId(aip,amp, atp);
  3184.    }
  3185.    if (atp == ENTREZ_TREE_CHILD_total) {
  3186.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3187.          goto erret;
  3188.       }
  3189.       ChildPtr -> total = av.intvalue;
  3190.       atp = AsnReadId(aip,amp, atp);
  3191.    }
  3192.  
  3193.    if (AsnReadVal(aip, atp, &av) <= 0) {
  3194.       goto erret;
  3195.    }
  3196.    /* end struct */
  3197.  
  3198. ret:
  3199.    AsnUnlinkType(orig);       /* unlink local tree */
  3200.    return ChildPtr;
  3201.  
  3202. erret:
  3203.    ChildLinkFree(ChildPtr);
  3204.    goto ret;
  3205. }
  3206.  
  3207.  
  3208.  
  3209. /**************************************************
  3210. *
  3211. *    ChildLinkAsnWrite()
  3212. *
  3213. **************************************************/
  3214. static Boolean LIBCALL 
  3215. ChildLinkAsnWrite(ChildLinkPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
  3216. {
  3217.    DataVal av;
  3218.    AsnTypePtr atp;
  3219.    Boolean retval = FALSE;
  3220.  
  3221.    if (! loaded)
  3222.    {
  3223.       if (! NetEntAsnLoad()) {
  3224.          return FALSE;
  3225.       }
  3226.    }
  3227.  
  3228.    if (aip == NULL) {
  3229.       return FALSE;
  3230.    }
  3231.  
  3232.    atp = AsnLinkType(orig, ENTREZ_TREE_CHILD);   /* link local tree */
  3233.    if (atp == NULL) {
  3234.       return FALSE;
  3235.    }
  3236.  
  3237.    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
  3238.  
  3239.    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
  3240.       goto erret;
  3241.    }
  3242.  
  3243.    if (ptr -> name != NULL) {
  3244.       av.ptrvalue = ptr -> name;
  3245.       retval = AsnWrite(aip, ENTREZ_TREE_CHILD_name,  &av);
  3246.    }
  3247.    av.boolvalue = ptr -> isLeafNode;
  3248.    retval = AsnWrite(aip, ENTREZ_TREE_CHILD_is_leaf_node,  &av);
  3249.    av.intvalue = ptr -> special;
  3250.    retval = AsnWrite(aip, ENTREZ_TREE_CHILD_special,  &av);
  3251.    av.intvalue = ptr -> total;
  3252.    retval = AsnWrite(aip, ENTREZ_TREE_CHILD_total,  &av);
  3253.    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
  3254.       goto erret;
  3255.    }
  3256.    retval = TRUE;
  3257.  
  3258. erret:
  3259.    AsnUnlinkType(orig);       /* unlink local tree */
  3260.    return retval;
  3261. }
  3262.  
  3263. static EntrezHierarchyChildPtr ChildLinkedListToArray(ChildLinkPtr Link, 
  3264.                                         Int4 numChildren)
  3265. {
  3266.   Int4 Index = 0;
  3267.   EntrezHierarchyChildPtr Array;
  3268.  
  3269.   if (numChildren <= 0)
  3270.     return NULL;
  3271.  
  3272.   Array = MemNew(sizeof(EntrezHierarchyChild) * numChildren);
  3273.   while (Link != NULL)
  3274.     {
  3275.       Array[Index].name = StringSave(Link -> name);
  3276.       Array[Index].isLeafNode = Link -> isLeafNode;
  3277.       Array[Index].special = Link -> special;
  3278.       Array[Index].total = Link -> total;
  3279.       Index++;
  3280.       Link = Link -> next;
  3281.     }
  3282.  
  3283.   if (Index != numChildren)
  3284.     {
  3285.       fprintf(stderr,"ChildLinkedListToArray : counts do not match!\n");
  3286.       exit (0);
  3287.     }
  3288.  
  3289.   return Array;
  3290. }
  3291.  
  3292. static ChildLinkPtr ArrayToChildLinkedList(
  3293.                 EntrezHierarchyChildPtr Array, 
  3294.                 Int4 numChildren)
  3295. {
  3296.   Int4 Index;
  3297.   ChildLinkPtr Link, Start;
  3298.  
  3299.   if (numChildren <= 0)
  3300.     return NULL;
  3301.  
  3302.   for (Index = 0; Index < numChildren; Index++)
  3303.     {
  3304.       if (Index == 0)
  3305.         Start = Link = ChildLinkNew();
  3306.       else
  3307.         {
  3308.           Link -> next = ChildLinkNew();
  3309.           Link = Link -> next;
  3310.         }
  3311.  
  3312.       Link -> name = StringSave(Array[Index].name);
  3313.       Link -> isLeafNode = Array[Index].isLeafNode;
  3314.       Link -> special = Array[Index].special;
  3315.       Link -> total = Array[Index].total;
  3316.     }
  3317.  
  3318.   Link -> next = NULL;
  3319.   return (Start);
  3320.         
  3321. }
  3322.  
  3323. static CharPtr PNTR LineageListToArray(ValNodePtr Lineage, 
  3324.                                        Int4 numInLineage)
  3325. {
  3326.   CharPtr PNTR start;
  3327.   CharPtr PNTR ptr;
  3328.  
  3329.   if (numInLineage <= 0)
  3330.     return NULL;
  3331.  
  3332.   start = ptr = MemNew(sizeof(CharPtr) * numInLineage);
  3333.   while (Lineage != NULL)
  3334.     {
  3335.       *ptr++ = StringSave(Lineage -> data.ptrvalue);
  3336.       Lineage = Lineage -> next;
  3337.     }
  3338.  
  3339.   if ((long) (ptr - start) != numInLineage)
  3340.     {
  3341.       fprintf(stderr,"mismatch in LineageListToArray!\n");
  3342.       exit (0);
  3343.     }
  3344.  
  3345.   return start;
  3346. }
  3347.  
  3348. static ValNodePtr LineageArrayToList(CharPtr PNTR Lineage, Int4 numInLineage)
  3349. {
  3350.   ValNodePtr ptr, start;
  3351.   Int4 index;
  3352.  
  3353.   if (numInLineage <= 0)
  3354.     return NULL;
  3355.  
  3356.   for (index = 0; index < numInLineage; index++)
  3357.     {
  3358.       if (index == 0)
  3359.         {
  3360.           start = ptr = MemNew(sizeof(ValNode));
  3361.         }
  3362.       else
  3363.         {
  3364.           ptr -> next = MemNew(sizeof(ValNode));
  3365.           ptr = ptr ->next;
  3366.         }
  3367.  
  3368.       ptr -> choice = 0;
  3369.       ptr -> data.ptrvalue = StringSave(Lineage[index]);
  3370.     }
  3371.  
  3372.   ptr -> next = NULL;
  3373.  
  3374.   return start;
  3375. }
  3376.  
  3377. static void FreeLineageList(ValNodePtr ptr)
  3378. {
  3379.   ValNodePtr next;
  3380.  
  3381.   while(ptr != NULL)
  3382.     {
  3383.       next = ptr ->next;
  3384.       MemFree(ptr -> data.ptrvalue);
  3385.       MemFree(ptr);
  3386.       ptr = next;
  3387.     }
  3388. }
  3389.       
  3390.           
  3391. /**************************************************
  3392. *
  3393. *    EntrezHierarchyNew()
  3394. *
  3395. **************************************************/
  3396.  
  3397. EntrezHierarchyPtr LIBCALL EntrezHierarchyNew(void)
  3398. {
  3399.    EntrezHierarchyPtr ptr = MemNew((size_t) sizeof(EntrezHierarchy));
  3400.    return ptr;
  3401. }
  3402.  
  3403.  
  3404. /**************************************************
  3405. *
  3406. *    EntrezHierarchyFree() is defined in accentr.c
  3407. *
  3408. **************************************************/
  3409.  
  3410.  
  3411.  
  3412. /**************************************************
  3413. *
  3414. *    EntrezHierarchyAsnRead()
  3415. *
  3416. **************************************************/
  3417.  
  3418. EntrezHierarchyPtr LIBCALL EntrezHierarchyAsnRead(AsnIoPtr aip, AsnTypePtr orig)
  3419. {
  3420.   DataVal av;
  3421.   AsnTypePtr atp;
  3422.   Boolean isError;
  3423.   AsnReadFunc func;
  3424.   EntrezHierarchyPtr ptr;
  3425.   ChildLinkPtr ChildLinkedList;
  3426.   ValNodePtr LineageList;
  3427.  
  3428.   if (! loaded)
  3429.     {
  3430.       if (! NetEntAsnLoad()) 
  3431.         {
  3432.           return NULL;
  3433.         }
  3434.     }
  3435.   
  3436.   if (aip == NULL) 
  3437.     {
  3438.       return NULL;
  3439.     }
  3440.   
  3441.   if (orig == NULL) 
  3442.     {         /* EntrezHierarchy ::= (self contained) */
  3443.       atp = AsnReadId(aip, amp, ENTREZ_TREE);
  3444.     }
  3445.   else     
  3446.     {
  3447.       atp = AsnLinkType(orig, ENTREZ_TREE);
  3448.     }
  3449.   /* link in local tree */
  3450.   if (atp == NULL) 
  3451.     {
  3452.       return NULL;
  3453.     }
  3454.   
  3455.   ptr = EntrezHierarchyNew();
  3456.   if (ptr == NULL) 
  3457.     {
  3458.       goto erret;
  3459.     }
  3460.   if (AsnReadVal(aip, atp, &av) <= 0) 
  3461.     { /* read the start struct */
  3462.       goto erret;
  3463.     }
  3464.   
  3465.   func = NULL;
  3466.   
  3467.   atp = AsnReadId(aip,amp, atp);
  3468.   if (atp == ENTREZ_TREE_num_in_lineage) 
  3469.     {
  3470.       if ( AsnReadVal(aip, atp, &av) <= 0) 
  3471.         {
  3472.           goto erret;
  3473.         }
  3474.       ptr -> numInLineage = av.intvalue;
  3475.       atp = AsnReadId(aip,amp, atp);
  3476.     }
  3477.   if (atp == ENTREZ_TREE_num_children) 
  3478.     {
  3479.       if ( AsnReadVal(aip, atp, &av) <= 0) 
  3480.         {
  3481.           goto erret;
  3482.         }
  3483.       ptr -> numChildren = av.intvalue;
  3484.       atp = AsnReadId(aip,amp, atp);
  3485.     }
  3486.   if (atp == ENTREZ_TREE_term) 
  3487.     {
  3488.       if ( AsnReadVal(aip, atp, &av) <= 0) 
  3489.         {
  3490.           goto erret;
  3491.         }
  3492.       ptr -> term = av.ptrvalue;
  3493.       atp = AsnReadId(aip,amp, atp);
  3494.     }
  3495.   if (atp == ENTREZ_TREE_lineage) 
  3496.     {
  3497.       LineageList = AsnGenericBaseSeqOfAsnRead(aip, amp, atp, ASNCODE_PTRVAL_SLOT, &isError);
  3498.       if (isError && LineageList == NULL) 
  3499.         
  3500.         {
  3501.           goto erret;
  3502.         }
  3503.       ptr -> lineage = LineageListToArray(LineageList, 
  3504.                                           ptr->numInLineage);
  3505.       FreeLineageList(LineageList);
  3506.       atp = AsnReadId(aip,amp, atp);
  3507.     }
  3508.   
  3509.   if (atp == ENTREZ_TREE_children) 
  3510.     {
  3511.       ChildLinkedList = AsnGenericUserSeqOfAsnRead(aip, amp, atp, &isError, 
  3512.                            (AsnReadFunc) ChildLinkAsnRead, 
  3513.                            (AsnOptFreeFunc) ChildLinkFree);
  3514.       if (isError && ChildLinkedList == NULL) 
  3515.         
  3516.         {
  3517.           goto erret;
  3518.         }
  3519.       ptr -> children = ChildLinkedListToArray(ChildLinkedList,
  3520.                                                ptr ->numChildren);
  3521.       ChildLinkedListFree(ChildLinkedList);
  3522.       atp = AsnReadId(aip,amp, atp);
  3523.     }
  3524.   if (atp == ENTREZ_TREE_canonical_form) 
  3525.     {
  3526.       if ( AsnReadVal(aip, atp, &av) <= 0) 
  3527.         {
  3528.           goto erret;
  3529.         }
  3530.       ptr -> canonicalForm = av.ptrvalue;
  3531.       atp = AsnReadId(aip,amp, atp);
  3532.     }
  3533.   
  3534.   if (AsnReadVal(aip, atp, &av) <= 0) 
  3535.     {
  3536.       goto erret;
  3537.     }
  3538.   /* end struct */
  3539.   
  3540.  ret:
  3541.   AsnUnlinkType(orig);       /* unlink local tree */
  3542.   return ptr;
  3543.   
  3544.  erret:
  3545.   ptr = EntrezHierarchyFree(ptr);
  3546.   goto ret;
  3547. }
  3548.  
  3549.  
  3550.  
  3551. /**************************************************
  3552. *
  3553. *    EntrezHierarchyAsnWrite()
  3554. *
  3555. **************************************************/
  3556. Boolean LIBCALL 
  3557. EntrezHierarchyAsnWrite(EntrezHierarchyPtr ptr, AsnIoPtr aip, 
  3558.                         AsnTypePtr orig)
  3559.      
  3560. {
  3561.   DataVal av;
  3562.   AsnTypePtr atp;
  3563.   Boolean retval = FALSE;
  3564.   ValNodePtr LineageList;
  3565.   ChildLinkPtr ChildLinkedList;
  3566.   
  3567.   if (! loaded)
  3568.     {
  3569.       if (! NetEntAsnLoad()) 
  3570.         {
  3571.           return FALSE;
  3572.         }
  3573.     }
  3574.   
  3575.   if (aip == NULL) 
  3576.     {
  3577.       return FALSE;
  3578.     }
  3579.   
  3580.   atp = AsnLinkType(orig, ENTREZ_TREE);   /* link local tree */
  3581.   if (atp == NULL) 
  3582.     {
  3583.       return FALSE;
  3584.     }
  3585.   
  3586.   if (ptr == NULL) 
  3587.     { 
  3588.       AsnNullValueMsg(aip, atp); goto erret; 
  3589.     }
  3590.   
  3591.   if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) 
  3592.     {
  3593.       goto erret;
  3594.     }
  3595.   
  3596.   av.intvalue = ptr -> numInLineage;
  3597.   retval = AsnWrite(aip, ENTREZ_TREE_num_in_lineage,  &av);
  3598.   av.intvalue = ptr -> numChildren;
  3599.   retval = AsnWrite(aip, ENTREZ_TREE_num_children,  &av);
  3600.   if (ptr -> term != NULL) 
  3601.     {
  3602.       av.ptrvalue = ptr -> term;
  3603.       retval = AsnWrite(aip, ENTREZ_TREE_term,  &av);
  3604.     }
  3605.   
  3606.   LineageList = LineageArrayToList(ptr -> lineage,ptr -> numInLineage);
  3607.   retval = AsnGenericBaseSeqOfAsnWrite(LineageList ,ASNCODE_PTRVAL_SLOT,
  3608.                                        aip,ENTREZ_TREE_lineage, 
  3609.                                        ENTREZ_TREE_lineage_E);
  3610.   FreeLineageList(LineageList);
  3611.   
  3612.   ChildLinkedList = ArrayToChildLinkedList(ptr -> children,ptr->numChildren);
  3613.   AsnGenericUserSeqOfAsnWrite(ChildLinkedList, 
  3614.                               (AsnWriteFunc) ChildLinkAsnWrite, aip,
  3615.                               ENTREZ_TREE_children, ENTREZ_TREE_children_E);
  3616.   ChildLinkedListFree(ChildLinkedList);
  3617.   
  3618.   if (ptr -> canonicalForm != NULL) 
  3619.     {
  3620.       av.ptrvalue = ptr -> canonicalForm;
  3621.       retval = AsnWrite(aip, ENTREZ_TREE_canonical_form,  &av);
  3622.     }
  3623.   if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) 
  3624.     {  
  3625.       goto erret;
  3626.     }
  3627.   retval = TRUE;
  3628.   
  3629.  erret:
  3630.   AsnUnlinkType(orig);       /* unlink local tree */
  3631.   return retval;
  3632. }
  3633.  
  3634.  
  3635. /**************************************************
  3636. *
  3637. *    EntrezBlastreqNew()
  3638. *
  3639. **************************************************/
  3640.  
  3641. EntrezBlastreqPtr LIBCALL
  3642. EntrezBlastreqNew(void)
  3643. {
  3644.    EntrezBlastreqPtr ptr = MemNew((size_t) sizeof(EntrezBlastreq));
  3645.  
  3646.    ptr->showprogress = FALSE;
  3647.  
  3648.    return ptr;
  3649.  
  3650. }
  3651.  
  3652.  
  3653. /**************************************************
  3654. *
  3655. *    EntrezBlastreqFree()
  3656. *
  3657. **************************************************/
  3658.  
  3659. EntrezBlastreqPtr LIBCALL
  3660. EntrezBlastreqFree(EntrezBlastreqPtr ptr)
  3661. {
  3662.  
  3663.    if(ptr == NULL) {
  3664.       return NULL;
  3665.    }
  3666.    BioseqFree(ptr -> bsp);
  3667.    MemFree(ptr -> program);
  3668.    MemFree(ptr -> database);
  3669.    MemFree(ptr -> options);
  3670.    return MemFree(ptr);
  3671. }
  3672.  
  3673.  
  3674. /**************************************************
  3675. *
  3676. *    EntrezBlastreqAsnRead()
  3677. *
  3678. **************************************************/
  3679.  
  3680. EntrezBlastreqPtr LIBCALL
  3681. EntrezBlastreqAsnRead(AsnIoPtr aip, AsnTypePtr orig)
  3682. {
  3683.    DataVal av;
  3684.    AsnTypePtr atp;
  3685.    Boolean isError = FALSE;
  3686.    AsnReadFunc func;
  3687.    EntrezBlastreqPtr ptr;
  3688.  
  3689.    if (! loaded)
  3690.    {
  3691.       if (! NetEntAsnLoad()) {
  3692.          return NULL;
  3693.       }
  3694.    }
  3695.  
  3696.    if (aip == NULL) {
  3697.       return NULL;
  3698.    }
  3699.  
  3700.    if (orig == NULL) {         /* EntrezBlastreq ::= (self contained) */
  3701.       atp = AsnReadId(aip, amp, ENTREZ_BLASTREQ);
  3702.    } else {
  3703.       atp = AsnLinkType(orig, ENTREZ_BLASTREQ);
  3704.    }
  3705.    /* link in local tree */
  3706.    if (atp == NULL) {
  3707.       return NULL;
  3708.    }
  3709.  
  3710.    ptr = EntrezBlastreqNew();
  3711.    if (ptr == NULL) {
  3712.       goto erret;
  3713.    }
  3714.    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
  3715.       goto erret;
  3716.    }
  3717.  
  3718.    atp = AsnReadId(aip,amp, atp);
  3719.    func = NULL;
  3720.  
  3721.    if (atp == ENTREZ_BLASTREQ_bsp) {
  3722.       ptr -> bsp = BioseqAsnRead(aip, atp);
  3723.       if (aip -> io_failure) {
  3724.          goto erret;
  3725.       }
  3726.       atp = AsnReadId(aip,amp, atp);
  3727.    }
  3728.    if (atp == ENTREZ_BLASTREQ_bsp_database) {
  3729.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3730.          goto erret;
  3731.       }
  3732.       ptr -> bsp_database = av.intvalue;
  3733.       atp = AsnReadId(aip,amp, atp);
  3734.    }
  3735.    if (atp == ENTREZ_BLASTREQ_program) {
  3736.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3737.          goto erret;
  3738.       }
  3739.       ptr -> program = av.ptrvalue;
  3740.       atp = AsnReadId(aip,amp, atp);
  3741.    }
  3742.    if (atp == ENTREZ_BLASTREQ_database) {
  3743.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3744.          goto erret;
  3745.       }
  3746.       ptr -> database = av.ptrvalue;
  3747.       atp = AsnReadId(aip,amp, atp);
  3748.    }
  3749.    if (atp == ENTREZ_BLASTREQ_options) {
  3750.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3751.          goto erret;
  3752.       }
  3753.       ptr -> options = av.ptrvalue;
  3754.       atp = AsnReadId(aip,amp, atp);
  3755.    }
  3756.    if (atp == ENTREZ_BLASTREQ_showprogress) {
  3757.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3758.          goto erret;
  3759.       }
  3760.       ptr -> showprogress = av.boolvalue;
  3761.       atp = AsnReadId(aip,amp, atp);
  3762.    }
  3763.  
  3764.    if (AsnReadVal(aip, atp, &av) <= 0) {
  3765.       goto erret;
  3766.    }
  3767.    /* end struct */
  3768.  
  3769. ret:
  3770.    AsnUnlinkType(orig);       /* unlink local tree */
  3771.    return ptr;
  3772.  
  3773. erret:
  3774.    aip -> io_failure = TRUE;
  3775.    ptr = EntrezBlastreqFree(ptr);
  3776.    goto ret;
  3777. }
  3778.  
  3779.  
  3780.  
  3781. /**************************************************
  3782. *
  3783. *    EntrezBlastreqAsnWrite()
  3784. *
  3785. **************************************************/
  3786. Boolean LIBCALL 
  3787. EntrezBlastreqAsnWrite(EntrezBlastreqPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
  3788. {
  3789.    DataVal av;
  3790.    AsnTypePtr atp;
  3791.    Boolean retval = FALSE;
  3792.  
  3793.    if (! loaded)
  3794.    {
  3795.       if (! NetEntAsnLoad()) {
  3796.          return FALSE;
  3797.       }
  3798.    }
  3799.  
  3800.    if (aip == NULL) {
  3801.       return FALSE;
  3802.    }
  3803.  
  3804.    atp = AsnLinkType(orig, ENTREZ_BLASTREQ);   /* link local tree */
  3805.    if (atp == NULL) {
  3806.       return FALSE;
  3807.    }
  3808.  
  3809.    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
  3810.    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
  3811.       goto erret;
  3812.    }
  3813.  
  3814.    if (ptr -> bsp != NULL) {
  3815.       if ( ! BioseqAsnWrite(ptr -> bsp, aip, ENTREZ_BLASTREQ_bsp)) {
  3816.          goto erret;
  3817.       }
  3818.    }
  3819.    av.intvalue = ptr -> bsp_database;
  3820.    retval = AsnWrite(aip, ENTREZ_BLASTREQ_bsp_database,  &av);
  3821.    if (ptr -> program != NULL) {
  3822.       av.ptrvalue = ptr -> program;
  3823.       retval = AsnWrite(aip, ENTREZ_BLASTREQ_program,  &av);
  3824.    }
  3825.    if (ptr -> database != NULL) {
  3826.       av.ptrvalue = ptr -> database;
  3827.       retval = AsnWrite(aip, ENTREZ_BLASTREQ_database,  &av);
  3828.    }
  3829.    if (ptr -> options != NULL) {
  3830.       av.ptrvalue = ptr -> options;
  3831.       retval = AsnWrite(aip, ENTREZ_BLASTREQ_options,  &av);
  3832.    }
  3833.    av.boolvalue = ptr -> bsp_database;
  3834.    retval = AsnWrite(aip, ENTREZ_BLASTREQ_showprogress,  &av);
  3835.    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
  3836.       goto erret;
  3837.    }
  3838.    retval = TRUE;
  3839.  
  3840. erret:
  3841.    AsnUnlinkType(orig);       /* unlink local tree */
  3842.    return retval;
  3843. }
  3844.  
  3845.  
  3846.  
  3847. /**************************************************
  3848. *
  3849. *    EntrezExtraInfoNew()
  3850. *
  3851. **************************************************/
  3852.  
  3853. EntrezExtraInfoPtr LIBCALL
  3854. EntrezExtraInfoNew(void)
  3855. {
  3856.    EntrezExtraInfoPtr ptr = MemNew((size_t) sizeof(EntrezExtraInfo));
  3857.  
  3858.    return ptr;
  3859.  
  3860. }
  3861.  
  3862.  
  3863. /**************************************************
  3864. *
  3865. *    EntrezExtraInfoFree()
  3866. *
  3867. **************************************************/
  3868.  
  3869. EntrezExtraInfoPtr LIBCALL
  3870. EntrezExtraInfoFree(EntrezExtraInfoPtr ptr)
  3871. {
  3872.  
  3873.    if(ptr == NULL) {
  3874.       return NULL;
  3875.    }
  3876.    return MemFree(ptr);
  3877. }
  3878.  
  3879.  
  3880. /**************************************************
  3881. *
  3882. *    EntrezExtraInfoAsnRead()
  3883. *
  3884. **************************************************/
  3885.  
  3886. EntrezExtraInfoPtr LIBCALL
  3887. EntrezExtraInfoAsnRead(AsnIoPtr aip, AsnTypePtr orig)
  3888. {
  3889.    DataVal av;
  3890.    AsnTypePtr atp;
  3891.    Boolean isError = FALSE;
  3892.    AsnReadFunc func;
  3893.    EntrezExtraInfoPtr ptr;
  3894.  
  3895.    if (! loaded)
  3896.    {
  3897.       if (! NetEntAsnLoad()) {
  3898.          return NULL;
  3899.       }
  3900.    }
  3901.  
  3902.    if (aip == NULL) {
  3903.       return NULL;
  3904.    }
  3905.  
  3906.    if (orig == NULL) {         /* EntrezExtraInfo ::= (self contained) */
  3907.       atp = AsnReadId(aip, amp, ENTREZ_EXTRA_INFO);
  3908.    } else {
  3909.       atp = AsnLinkType(orig, ENTREZ_EXTRA_INFO);
  3910.    }
  3911.    /* link in local tree */
  3912.    if (atp == NULL) {
  3913.       return NULL;
  3914.    }
  3915.  
  3916.    ptr = EntrezExtraInfoNew();
  3917.    if (ptr == NULL) {
  3918.       goto erret;
  3919.    }
  3920.    if (AsnReadVal(aip, atp, &av) <= 0) { /* read the start struct */
  3921.       goto erret;
  3922.    }
  3923.  
  3924.    atp = AsnReadId(aip,amp, atp);
  3925.    func = NULL;
  3926.  
  3927.    if (atp == ENTREZ_EXTRA_INFO_maxlinks) {
  3928.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3929.          goto erret;
  3930.       }
  3931.       ptr -> maxlinks = av.intvalue;
  3932.       atp = AsnReadId(aip,amp, atp);
  3933.    }
  3934.    if (atp == EXTRA_INFO_canneighbortext) {
  3935.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3936.          goto erret;
  3937.       }
  3938.       ptr -> canneighbortext = av.boolvalue;
  3939.       atp = AsnReadId(aip,amp, atp);
  3940.    }
  3941.    if (atp == EXTRA_INFO_expanded_medline) {
  3942.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3943.          goto erret;
  3944.       }
  3945.       ptr -> expanded_medline = av.boolvalue;
  3946.       atp = AsnReadId(aip,amp, atp);
  3947.    }
  3948.    if (atp == ENTREZ_EXTRA_INFO_canblast) {
  3949.       if ( AsnReadVal(aip, atp, &av) <= 0) {
  3950.          goto erret;
  3951.       }
  3952.       ptr -> canblast = av.boolvalue;
  3953.       atp = AsnReadId(aip,amp, atp);
  3954.    }
  3955.  
  3956.    if (AsnReadVal(aip, atp, &av) <= 0) {
  3957.       goto erret;
  3958.    }
  3959.    /* end struct */
  3960.  
  3961. ret:
  3962.    AsnUnlinkType(orig);       /* unlink local tree */
  3963.    return ptr;
  3964.  
  3965. erret:
  3966.    aip -> io_failure = TRUE;
  3967.    ptr = EntrezExtraInfoFree(ptr);
  3968.    goto ret;
  3969. }
  3970.  
  3971.  
  3972.  
  3973. /**************************************************
  3974. *
  3975. *    EntrezExtraInfoAsnWrite()
  3976. *
  3977. **************************************************/
  3978. Boolean LIBCALL 
  3979. EntrezExtraInfoAsnWrite(EntrezExtraInfoPtr ptr, AsnIoPtr aip, AsnTypePtr orig)
  3980. {
  3981.    DataVal av;
  3982.    AsnTypePtr atp;
  3983.    Boolean retval = FALSE;
  3984.  
  3985.    if (! loaded)
  3986.    {
  3987.       if (! NetEntAsnLoad()) {
  3988.          return FALSE;
  3989.       }
  3990.    }
  3991.  
  3992.    if (aip == NULL) {
  3993.       return FALSE;
  3994.    }
  3995.  
  3996.    atp = AsnLinkType(orig, ENTREZ_EXTRA_INFO);   /* link local tree */
  3997.    if (atp == NULL) {
  3998.       return FALSE;
  3999.    }
  4000.  
  4001.    if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }
  4002.    if (! AsnOpenStruct(aip, atp, (Pointer) ptr)) {
  4003.       goto erret;
  4004.    }
  4005.  
  4006.    av.intvalue = ptr -> maxlinks;
  4007.    retval = AsnWrite(aip, ENTREZ_EXTRA_INFO_maxlinks,  &av);
  4008.    av.boolvalue = ptr -> canneighbortext;
  4009.    retval = AsnWrite(aip, EXTRA_INFO_canneighbortext,  &av);
  4010.    av.boolvalue = ptr -> expanded_medline;
  4011.    retval = AsnWrite(aip, EXTRA_INFO_expanded_medline,  &av);
  4012.    av.boolvalue = ptr -> canblast;
  4013.    retval = AsnWrite(aip, ENTREZ_EXTRA_INFO_canblast,  &av);
  4014.    if (! AsnCloseStruct(aip, atp, (Pointer)ptr)) {
  4015.       goto erret;
  4016.    }
  4017.    retval = TRUE;
  4018.  
  4019. erret:
  4020.    AsnUnlinkType(orig);       /* unlink local tree */
  4021.    return retval;
  4022. }
  4023.  
  4024.  
  4025. /************************** NewSummaryList ****************************************/
  4026.  
  4027. NewSummaryListPtr LIBCALL
  4028. NewSummaryListNew(void)
  4029. {
  4030.         NewSummaryListPtr p;
  4031.  
  4032.         p = MemNew(sizeof(NewSummaryList));
  4033.         if (p != NULL)
  4034.         {
  4035.                 p->num = 0;
  4036.                 p->data = NULL;
  4037.         }
  4038.         return p;
  4039. }
  4040.  
  4041. NewSummaryListPtr LIBCALL
  4042. NewSummaryListFree(NewSummaryListPtr p)
  4043. {
  4044.         Int4 i;
  4045.  
  4046.         if (p == NULL)
  4047.                 return NULL;
  4048.         if (p->data != NULL)
  4049.         {
  4050.                 for (i = 0; i < p->num; i++)
  4051.                         DocSumFree(p->data[i]);
  4052.         }
  4053.         MemFree (p->data);
  4054.         return MemFree(p);
  4055. }
  4056.                 
  4057. NewSummaryListPtr LIBCALL
  4058. NewSummaryListAsnRead (AsnIoPtr aip, AsnTypePtr orig)
  4059. {
  4060.         DataVal av;
  4061.         NewSummaryListPtr p;
  4062.         AsnTypePtr atp;
  4063.         Int4 num;
  4064.  
  4065.         if (!NetEntAsnLoad())
  4066.                 return NULL;
  4067.         
  4068.         if (aip == NULL)
  4069.                 return NULL;
  4070.         
  4071.         if (orig == NULL)
  4072.                 atp = AsnReadId(aip, amp, NEW_SUMMARY_LIST);
  4073.         else
  4074.                 atp = AsnLinkType(orig, NEW_SUMMARY_LIST); /* link in local tree */
  4075.  
  4076.         if (atp == NULL)
  4077.                 return NULL;
  4078.  
  4079.         p = NewSummaryListNew();
  4080.         if (p == NULL)
  4081.                 goto erret;
  4082.  
  4083.         if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */
  4084.                 goto erret;
  4085.  
  4086.         atp = AsnReadId(aip, amp, atp); /* find the num */
  4087.         if (atp == NULL)
  4088.                 goto erret;
  4089.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */
  4090.                 goto erret;
  4091.         p->num = av.intvalue;
  4092.  
  4093.         atp = AsnReadId(aip, amp, atp); /* find the type */
  4094.         if (atp == NULL)
  4095.                 goto erret;
  4096.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the type */
  4097.                 goto erret;
  4098.         p->type = av.intvalue;
  4099.  
  4100.         atp = AsnReadId(aip, amp, atp); /* find the data start-struct */
  4101.         if (atp == NULL)
  4102.                 goto erret;
  4103.         if (AsnReadVal(aip, atp, &av) <= 0) /* get the data start-struct */
  4104.                 goto erret;
  4105.  
  4106.         p->data = (DocSumPtr PNTR) MemNew(sizeof(DocSumPtr) * (size_t) p->num);
  4107.         for (num = 0; num < p->num; num++)
  4108.                 p->data[num] = NULL;
  4109.         atp = AsnReadId(aip, amp, atp);
  4110.  
  4111.         for (num = 0; num < p->num && atp == NEW_SUMMARY_LIST_data_E; num++)
  4112.         {
  4113.                 if ((p->data[num] = DocSumAsnRead(aip, atp)) == NULL)
  4114.                         goto erret;
  4115.                 atp = AsnReadId(aip, amp, atp);
  4116.         }
  4117.  
  4118.         /* check for count mis-match */
  4119.         if (num != p->num || atp != NEW_SUMMARY_LIST_data)
  4120.                 goto erret;
  4121.  
  4122.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  4123.                 goto erret;
  4124.  
  4125.         atp = AsnReadId(aip, amp, atp);
  4126.         if (orig == NULL)
  4127.         {
  4128.                 if (atp != NEW_SUMMARY_LIST)
  4129.                         goto erret;
  4130.         }
  4131.         else { /* check for "close struct" associated with "orig" */
  4132.                 if (atp != orig)
  4133.                         goto erret;
  4134.         }
  4135.         if (AsnReadVal(aip, atp, NULL) <= 0) /* discard NULL */
  4136.                 goto erret;
  4137.  
  4138. ret:
  4139.         AsnUnlinkType(orig);
  4140.         return p;
  4141.  
  4142. erret:
  4143.         p = NewSummaryListFree(p);
  4144.         goto ret;
  4145. }
  4146.                 
  4147.  
  4148. Boolean LIBCALL
  4149. NewSummaryListAsnWrite (NewSummaryListPtr p, AsnIoPtr aip, AsnTypePtr orig)
  4150. {
  4151.         DataVal av;
  4152.         Int4 i;
  4153.         AsnTypePtr atp;
  4154.         Boolean retval = FALSE;
  4155.  
  4156.         if (! NetEntAsnLoad() )
  4157.                 return FALSE;
  4158.  
  4159.         if (aip == NULL)
  4160.                 return FALSE;
  4161.  
  4162.         atp = AsnLinkType(orig, NEW_SUMMARY_LIST); /* link local tree */
  4163.  
  4164.         if (atp == NULL)
  4165.                 return FALSE;
  4166.  
  4167.         if (p == NULL)
  4168.         {
  4169.                 AsnNullValueMsg(aip, atp);
  4170.                 goto erret;
  4171.         }
  4172.  
  4173.         if (! AsnStartStruct(aip, atp))
  4174.                 goto erret;
  4175.         av.intvalue = p->num;
  4176.         AsnWrite (aip, NEW_SUMMARY_LIST_num, &av);
  4177.         av.intvalue = p->type;
  4178.         AsnWrite (aip, NEW_SUMMARY_LIST_type, &av);
  4179.  
  4180.         AsnStartStruct (aip, NEW_SUMMARY_LIST_data);
  4181.         for (i = 0; i < p->num; i++)
  4182.         {
  4183.                 DocSumAsnWrite(p->data[i], aip, NEW_SUMMARY_LIST_data_E);
  4184.         }
  4185.         AsnEndStruct (aip, NEW_SUMMARY_LIST_data);
  4186.  
  4187.         if (! AsnEndStruct(aip, atp))
  4188.                 goto erret;
  4189.  
  4190.         retval = TRUE;
  4191.  
  4192. erret:
  4193.         AsnUnlinkType(orig); /* unlink local tree */
  4194.         return retval;
  4195. }
  4196.